Browse Source

Make the zone entry compile

Running the test happily crashes.

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac408@3658 e5f2f494-b856-4b98-b285-d166d9295462
Michal Vaner 14 years ago
parent
commit
d2a23b4636

+ 1 - 1
src/lib/nsas/Makefile.am

@@ -19,7 +19,7 @@ libnsas_la_SOURCES += nameserver_address.h
 libnsas_la_SOURCES += nameserver_entry.cc nameserver_entry.h
 libnsas_la_SOURCES += nsas_entry_compare.h
 libnsas_la_SOURCES += nsas_entry.h
-#libnsas_la_SOURCES += zone_entry.cc zone_entry.h
+libnsas_la_SOURCES += zone_entry.cc zone_entry.h
 libnsas_la_SOURCES += fetchable.h
 libnsas_la_SOURCES += address_request_callback.h
 libnsas_la_SOURCES += resolver_interface.h

+ 2 - 0
src/lib/nsas/nameserver_entry.h

@@ -110,6 +110,8 @@ public:
     /// possible optimisation if the caller has the current time (it saves
     /// the overhead of a call to time()).  The default value of 0 requests
     /// the constructor to get its own copy of the current time.
+    /// \todo This is possibly unneeded, if NSAS uses the resolver for
+    /// everything
     NameserverEntry(const isc::dns::AbstractRRset* v4Set,
         const isc::dns::AbstractRRset* v6Set, time_t curtime = 0);
 

+ 24 - 18
src/lib/nsas/tests/zone_entry_unittest.cc

@@ -42,15 +42,18 @@ class ZoneEntryTest : public TestWithRdata {
 protected:
     /// \brief Constructor
     ZoneEntryTest() :
-        nameservers_hash_(new NsasEntryCompare<NameserverEntry>),
-        nameservers_lru_((3 * nameservers_hash_.tableSize()),
-            new HashDeleter<NameserverEntry>(nameservers_hash_)),
+        nameserver_table_(new HashTable<NameserverEntry>(
+            new NsasEntryCompare<NameserverEntry>)),
+        nameserver_lru_(new LruList<NameserverEntry>(
+            (3 * nameserver_table_->tableSize()),
+            new HashDeleter<NameserverEntry>(*nameserver_table_))),
         resolver_(new TestResolver),
         callback_(new Callback)
     { }
     /// \brief Tables of nameservers to pass into zone entry constructor
-    HashTable<NameserverEntry> nameservers_hash_;
-    LruList<NameserverEntry> nameservers_lru_;
+    shared_ptr<HashTable<NameserverEntry> > nameserver_table_;
+    shared_ptr<LruList<NameserverEntry> > nameserver_lru_;
+    /// \brief The resolver
     shared_ptr<TestResolver> resolver_;
 
     struct Callback : public AddressRequestCallback {
@@ -70,13 +73,16 @@ class InheritedZoneEntry : public ZoneEntry {
     public:
         InheritedZoneEntry(shared_ptr<ResolverInterface> resolver,
             const isc::dns::AbstractRRset& authority,
-            HashTable<NameserverEntry>& nameservers,
-            LruList<NameserverEntry>& nameserver_lru) :
-            ZoneEntry(resolver, authority, nameservers, nameserver_lru)
+            shared_ptr<HashTable<NameserverEntry> > nameserver_table,
+            shared_ptr<LruList<NameserverEntry> > nameserver_lru) :
+            ZoneEntry(resolver, authority, nameserver_table, nameserver_lru)
         { }
         InheritedZoneEntry(shared_ptr<ResolverInterface> resolver,
-            const std::string& name, uint16_t class_code) :
-            ZoneEntry(resolver, name, class_code)
+            const std::string& name, uint16_t class_code,
+            shared_ptr<HashTable<NameserverEntry> > nameserver_table,
+            shared_ptr<LruList<NameserverEntry> > nameserver_lru) :
+            ZoneEntry(resolver, name, class_code, nameserver_table,
+                nameserver_lru)
         { }
         NameserverVector& nameservers() { return nameservers_; }
 };
@@ -86,7 +92,7 @@ TEST_F(ZoneEntryTest, DefaultConstructor) {
 
     // Default constructor should not create any RRsets
     InheritedZoneEntry alpha(resolver_, EXAMPLE_CO_UK,
-        RRClass::IN().getCode());
+        RRClass::IN().getCode(), nameserver_table_, nameserver_lru_);
     EXPECT_EQ(EXAMPLE_CO_UK, alpha.getName());
     EXPECT_EQ(RRClass::IN().getCode(), alpha.getClass());
     EXPECT_TRUE(alpha.nameservers().empty());
@@ -94,8 +100,8 @@ TEST_F(ZoneEntryTest, DefaultConstructor) {
 
 /// Tests of constructor from referral data
 TEST_F(ZoneEntryTest, ReferralConstructor) {
-    InheritedZoneEntry alpha(resolver_, rr_single_, nameservers_hash_,
-        nameservers_lru_);
+    InheritedZoneEntry alpha(resolver_, rr_single_, nameserver_table_,
+        nameserver_lru_);
     // It should load the name and class from the referral info
     EXPECT_EQ(EXAMPLE_CO_UK, alpha.getName());
     EXPECT_EQ(RRClass::IN().getCode(), alpha.getClass());
@@ -107,7 +113,7 @@ TEST_F(ZoneEntryTest, ReferralConstructor) {
 // It should answer negatively right away if there are no nameservers
 TEST_F(ZoneEntryTest, CallbackNoNS) {
     shared_ptr<InheritedZoneEntry> zone(new InheritedZoneEntry(resolver_,
-        rr_empty_, nameservers_hash_, nameservers_lru_));
+        rr_empty_, nameserver_table_, nameserver_lru_));
     // It should accept the callback
     EXPECT_TRUE(zone->addCallback(callback_, ANY_OK, zone));
     // And tell imediatelly that it is unreachable (when it has no nameservers)
@@ -120,7 +126,7 @@ TEST_F(ZoneEntryTest, CallbackZeroTTL) {
     // Make it zero TTL, so it expires right away
     rr_single_.setTTL(RRTTL(0));
     shared_ptr<InheritedZoneEntry> zone(new InheritedZoneEntry(resolver_,
-        rr_single_, nameservers_hash_, nameservers_lru_));
+        rr_single_, nameserver_table_, nameserver_lru_));
     // It should accept the callback
     EXPECT_TRUE(zone->addCallback(callback_, ANY_OK, zone));
     // It should not be answered yet, it should ask for the IP addresses
@@ -134,7 +140,7 @@ TEST_F(ZoneEntryTest, CallbackZeroTTL) {
 // Check it answers callbacks when we give it addresses
 TEST_F(ZoneEntryTest, CallbacksAnswered) {
     shared_ptr<InheritedZoneEntry> zone(new InheritedZoneEntry(resolver_,
-        rr_single_, nameservers_hash_, nameservers_lru_));
+        rr_single_, nameserver_table_, nameserver_lru_));
     // It should be in NOT_ASKED state
     EXPECT_EQ(Fetchable::NOT_ASKED, zone->getState());
     // It should accept the callback
@@ -178,7 +184,7 @@ TEST_F(ZoneEntryTest, CallbacksAnswered) {
 // Pretend the server can be reached only by IPv4
 TEST_F(ZoneEntryTest, CallbacksAOnly) {
     shared_ptr<InheritedZoneEntry> zone(new InheritedZoneEntry(resolver_,
-        rr_single_, nameservers_hash_, nameservers_lru_));
+        rr_single_, nameserver_table_, nameserver_lru_));
     // It should be in NOT_ASKED state
     EXPECT_EQ(Fetchable::NOT_ASKED, zone->getState());
     // It should accept the callback
@@ -221,7 +227,7 @@ TEST_F(ZoneEntryTest, CallbacksAOnly) {
 // See it tries hard enough to get address and tries both nameservers
 TEST_F(ZoneEntryTest, CallbackTwoNS) {
     shared_ptr<InheritedZoneEntry> zone(new InheritedZoneEntry(resolver_,
-        rrns_, nameservers_hash_, nameservers_lru_));
+        rrns_, nameserver_table_, nameserver_lru_));
     // It should be in NOT_ASKED state
     EXPECT_EQ(Fetchable::NOT_ASKED, zone->getState());
     // It should accept the callback

+ 21 - 45
src/lib/nsas/zone_entry.cc

@@ -25,62 +25,38 @@ using namespace std;
 using namespace boost;
 
 namespace isc {
+
+using namespace dns;
+
 namespace nsas {
 
 namespace {
 // Shorter aliases for frequently used types
-typedef mutex::scoped_lock LLock; // Local lock, nameservers not locked
-typedef shared_ptr<LLock> LockPtr;
-typedef vector<LockPtr> Locks;
+typedef mutex::scoped_lock Lock; // Local lock, nameservers not locked
 typedef shared_ptr<AddressRequestCallback> CallbackPtr;
 }
 
-void
-ZoneEntry::addCallback(CallbackPtr callback) {
-    LLock lock(mutex_);
-    callbacks_.push_back(callback);
+ZoneEntry::ZoneEntry(shared_ptr<ResolverInterface> resolver,
+    const AbstractRRset&,
+    shared_ptr<HashTable<NameserverEntry> > nameserver_table,
+    shared_ptr<LruList<NameserverEntry> > nameserver_lru) :
+    resolver_(resolver),
+    nameserver_table_(nameserver_table),
+    nameserver_lru_(nameserver_lru)
+{
+    // TODO get rid of this function
 }
 
 bool
-ZoneEntry::hasCallbacks() const {
-    LLock lock(mutex_);
-    return (!callbacks_.empty());
-}
-
-CallbackPtr
-ZoneEntry::popCallback() {
-    LLock lock(mutex_);
-    CallbackPtr result(callbacks_.front());
-    callbacks_.pop_front();
-    return (result);
-}
-
-// Struct, we are somewhere inside, no need to play the private & public game
-struct ZoneEntry::Lock::Impl {
-    Locks locks;
-};
-
-ZoneEntry::Lock::Lock(shared_ptr<Impl> impl) :
-    impl_(impl)
-{ }
-
-ZoneEntry::Lock
-ZoneEntry::getLock() {
-    // First, lock the zone so we can get the nameservers
-    LockPtr lock(new LLock(mutex_));
-    // Get a sorted copy of the nameservers
-    // They are sorted to avoid possible race conditions, they will be locked
-    // in increasing order
-    NameserverVector nameserverCopy(nameservers_);
-    sort(nameserverCopy.begin(), nameserverCopy.end());
-    // Construct the list of locks and lock all the nameservers
-    shared_ptr<Lock::Impl> impl(new Lock::Impl);
-    impl->locks.push_back(lock);
-    BOOST_FOREACH(NameserverPtr ns, nameserverCopy) {
-        impl->locks.push_back(LockPtr(new LLock(ns->mutex_)));
-    }
+ZoneEntry::addCallback(CallbackPtr callback,  AddressFamily family,
+    shared_ptr<ZoneEntry> self)
+{
+    // TODO: this is just stub now, to compile
+    (void) callback;
+    (void) family;
+    (void) self;
+    return (false);
 
-    return (Lock(impl));
 }
 
 }; // namespace nsas

+ 40 - 24
src/lib/nsas/zone_entry.h

@@ -50,33 +50,44 @@ class AddressRequestCallback;
 class ZoneEntry : public NsasEntry<ZoneEntry>, public Fetchable {
 public:
 
-    /// \brief Constructor where no NS records are supplied
-    ///
-    /// It is here mostly for testing purposes.
-    ///
-    /// \param resolver The resolver used to ask for IP addresses
-    /// \param name Name of the zone
-    /// \param class_code Class of this zone (zones of different classes have
-    /// different objects.
+    /**
+     * \brief Constructor where no NS records are supplied
+     *
+     * It is here mostly for testing purposes.
+     *
+     * \param resolver The resolver used to ask for IP addresses
+     * \param name Name of the zone
+     * \param class_code Class of this zone (zones of different classes have
+     *     different objects.
+     * \todo Move to cc file, include the lookup (if NSAS uses resolver for
+     *     everything)
+     */
     ZoneEntry(boost::shared_ptr<ResolverInterface> resolver,
-        const std::string& name, uint16_t class_code) :
-        name_(name), classCode_(class_code), resolver_(resolver)
+        const std::string& name, uint16_t class_code,
+        boost::shared_ptr<HashTable<NameserverEntry> > nameserver_table,
+        boost::shared_ptr<LruList<NameserverEntry> > nameserver_lru) :
+        name_(name), classCode_(class_code), resolver_(resolver),
+        nameserver_table_(nameserver_table), nameserver_lru_(nameserver_lru)
     {}
 
-    /// \brief Constructor
-    ///
-    /// Creates a zone entry object with an RRset representing the nameservers.
-    ///
-    /// \param resolver The resolver used to ask for IP addresses
-    /// \param authority Specifies the name, code and nameservers of this zone.
-    /// \param nameservers Hash table of existing nameserves and a place where
-    ///     new ones will be put.
-    /// \param nameserver_lru The lru where the nameservers will be added or
-    ///     touched.
+    /**
+     * \brief Constructor
+     *
+     * Creates a zone entry object with an RRset representing the nameservers.
+     *
+     * \param resolver The resolver used to ask for IP addresses
+     * \param authority Specifies the name, code and nameservers of this zone.
+     * \param nameserver_table Hash table of existing nameserves and a place
+     *     where new ones will be put.
+     * \param nameserver_lru The lru where the nameservers will be added or
+     *     touched.
+     * \todo This might be completely unneeded if NSAS uses resolver for
+     *     everything.
+     */
     ZoneEntry(boost::shared_ptr<ResolverInterface> resolver,
         const isc::dns::AbstractRRset& authority,
-        HashTable<NameserverEntry>& nameservers,
-        LruList<NameserverEntry>& nameserver_lru);
+        boost::shared_ptr<HashTable<NameserverEntry> > nameserver_table,
+        boost::shared_ptr<LruList<NameserverEntry> > nameserver_lru);
 
     /// \return Name of the zone
     std::string getName() const {
@@ -132,11 +143,16 @@ private:
     // callbacks. If nameserver is given, it is considered new and valid
     // even if its TTL is 0.
     void process(boost::shared_ptr<AddressRequestCallback> callback,
-         bool v4ok, bool v6ok, NameserverEntry* nameserver);
+         AddressFamily family, NameserverEntry* nameserver);
+    // Resolver we use
     boost::shared_ptr<ResolverInterface> resolver_;
+    // We store the nameserver table and lru, so we can look up when there's
+    // update
+    boost::shared_ptr<HashTable<NameserverEntry> > nameserver_table_;
+    boost::shared_ptr<LruList<NameserverEntry> > nameserver_lru_;
 };
 
 } // namespace nsas
 } // namespace isc
- 
+
 #endif // __ZONE_ENTRY_H