[svn] commit: r3372 - in /branches/trac356/src/lib/nsas: hash.cc hash.h hash_table.h lru_list.h nameserver_entry.cc nameserver_entry.h nsas_types.h zone_entry.h

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Oct 27 10:13:34 UTC 2010


Author: stephen
Date: Wed Oct 27 10:13:33 2010
New Revision: 3372

Log:
Modifications as result of code review

Modified:
    branches/trac356/src/lib/nsas/hash.cc
    branches/trac356/src/lib/nsas/hash.h
    branches/trac356/src/lib/nsas/hash_table.h
    branches/trac356/src/lib/nsas/lru_list.h
    branches/trac356/src/lib/nsas/nameserver_entry.cc
    branches/trac356/src/lib/nsas/nameserver_entry.h
    branches/trac356/src/lib/nsas/nsas_types.h
    branches/trac356/src/lib/nsas/zone_entry.h

Modified: branches/trac356/src/lib/nsas/hash.cc
==============================================================================
--- branches/trac356/src/lib/nsas/hash.cc (original)
+++ branches/trac356/src/lib/nsas/hash.cc Wed Oct 27 10:13:33 2010
@@ -63,6 +63,8 @@
 
 #include "hash.h"
 
+using namespace std;
+
 namespace isc {
 namespace nsas {
 
@@ -118,7 +120,9 @@
 }
 
 
-uint32_t Hash::operator()(const char* key, uint32_t keylen, bool ignorecase) {
+uint32_t Hash::operator()(const char* key, uint32_t keylen,
+    bool ignorecase) const
+{
 
     // Calculation as given in BIND-9.
     hash_accum_t partial_sum = 0;

Modified: branches/trac356/src/lib/nsas/hash.h
==============================================================================
--- branches/trac356/src/lib/nsas/hash.h (original)
+++ branches/trac356/src/lib/nsas/hash.h Wed Oct 27 10:13:33 2010
@@ -21,8 +21,6 @@
 #include <vector>
 
 #include "exceptions/exceptions.h"
-
-using namespace std;
 
 namespace isc {
 namespace nsas {
@@ -55,11 +53,15 @@
     /// \param maxkeylen Maximum length (in bytes) of a key to be hashed.
     /// calculation will return a value between 0 and N-1.  The default
     /// value of 255 is the maximum size of a DNS name.
-    /// \param randomise If true (the default), the pseudo-random number generator
-    /// is seeded with the current time.  Otherwise it is initialised to a known
-    /// sequence.  This is principally for unit tests, where a random sequence
-    /// could lead to problems in checking results.
+    /// \param randomise If true (the default), the pseudo-random number
+    /// generator is seeded with the current time.  Otherwise it is initialised
+    /// to a known sequence.  This is principally for unit tests, where a random
+    /// sequence could lead to problems in checking results.
     Hash(uint32_t tablesize, uint32_t maxkeylen = 255, bool randomise = true);
+
+    /// \bool Virtual Destructor
+    virtual ~Hash()
+    {}
 
     /// \brief Return Size
     ///
@@ -84,7 +86,8 @@
     /// hash value, false for it to be taken into account.
     ///
     /// \return Hash value, a number between 0 and N-1.
-    virtual uint32_t operator()(const char* key, uint32_t keylen, bool ignorecase = true);
+    virtual uint32_t operator()(const char* key, uint32_t keylen,
+        bool ignorecase = true) const;
 
     /// \brief Map Lower Case to Upper Case
     ///
@@ -94,7 +97,7 @@
     /// \param inchar Input character
     ///
     /// \return Mapped character
-    unsigned char mapLower(unsigned char inchar) {
+    virtual unsigned char mapLower(unsigned char inchar) const {
         return casemap_[inchar];
     }
 
@@ -111,8 +114,8 @@
 
     uint32_t        tablesize_;     ///< Size of the hash table
     uint32_t        maxkeylen_;     ///< Maximum key length
-    vector<unsigned char> casemap_; ///< Case mapping table
-    vector<hash_random_t> randvec_; ///< Vector of random numbers
+    std::vector<unsigned char> casemap_; ///< Case mapping table
+    std::vector<hash_random_t> randvec_; ///< Vector of random numbers
 
     static const uint32_t prime32_ = 0xfffffffb;    ///< 2^32 - 5
                                     ///< Specifies range of hash output

Modified: branches/trac356/src/lib/nsas/hash_table.h
==============================================================================
--- branches/trac356/src/lib/nsas/hash_table.h (original)
+++ branches/trac356/src/lib/nsas/hash_table.h Wed Oct 27 10:13:33 2010
@@ -29,7 +29,6 @@
 #include "hash.h"
 
 // Maximum key length if the maximum size of a DNS name
-#define HASHTABLE_SIZE 1009
 #define MAX_KEY_LENGTH 255
 
 using namespace std;

Modified: branches/trac356/src/lib/nsas/lru_list.h
==============================================================================
--- branches/trac356/src/lib/nsas/lru_list.h (original)
+++ branches/trac356/src/lib/nsas/lru_list.h Wed Oct 27 10:13:33 2010
@@ -105,6 +105,10 @@
         max_size_(max_size), count_(0), expired_(expired)
     {}
 
+    /// \brief Virtual Destructor
+    virtual ~LruList()
+    {}
+
     /// \brief Add Element
     ///
     /// Add a new element to the end of the list.
@@ -137,7 +141,7 @@
     /// some time if the list is big.
     ///
     /// \return Number of elements in the list
-    virtual uint32_t size() {
+    virtual uint32_t size() const {
 
         // Don't bother to lock the mutex.  If an update is in progress, we
         // receive either the value just before the update or just after it.
@@ -149,7 +153,7 @@
     /// \brief Return Maximum Size
     ///
     /// \return Maximum size of the list
-    virtual uint32_t getMaxSize() {
+    virtual uint32_t getMaxSize() const {
         return max_size_;
     }
 

Modified: branches/trac356/src/lib/nsas/nameserver_entry.cc
==============================================================================
--- branches/trac356/src/lib/nsas/nameserver_entry.cc (original)
+++ branches/trac356/src/lib/nsas/nameserver_entry.cc Wed Oct 27 10:13:33 2010
@@ -33,6 +33,8 @@
 #include "nameserver_entry.h"
 
 using namespace isc::nsas;
+using namespace isc::dns;
+using namespace std;
 
 namespace isc {
 namespace nsas {
@@ -40,8 +42,8 @@
 
 // Constructor, initialized with the list of addresses associated with this
 // nameserver.
-NameserverEntry::NameserverEntry(AbstractRRset* v4Set, AbstractRRset* v6Set,
-    time_t curtime) : expiration_(0)
+NameserverEntry::NameserverEntry(const AbstractRRset* v4Set,
+    const AbstractRRset* v6Set, time_t curtime) : expiration_(0)
 {
     // TODO: Use pseudo-random RTT
     uint32_t rtt = 0;       // Round-trip time for an address
@@ -156,6 +158,5 @@
     setAddressRTT(address, AddressEntry::UNREACHABLE);
 }
 
-
 } // namespace dns
 } // namespace isc

Modified: branches/trac356/src/lib/nsas/nameserver_entry.h
==============================================================================
--- branches/trac356/src/lib/nsas/nameserver_entry.h (original)
+++ branches/trac356/src/lib/nsas/nameserver_entry.h Wed Oct 27 10:13:33 2010
@@ -25,9 +25,6 @@
 #include "asiolink.h"
 #include "exceptions/exceptions.h"
 #include "rrset.h"
-
-using namespace std;
-using namespace isc::dns;
 
 namespace isc {
 namespace nsas {
@@ -82,7 +79,7 @@
     typedef std::vector<AddressEntry>   AddressVector;
     typedef AddressVector::iterator     AddressVectorIterator;
 
-    /// Constructor where no A records are supplied.
+    /// \brief Constructor where no A records are supplied.
     ///
     /// \param name Name of the nameserver,
     /// \param classCode class of the nameserver
@@ -102,7 +99,12 @@
     /// 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.
-    NameserverEntry(AbstractRRset* v4Set, AbstractRRset* v6Set, time_t curtime = 0);
+    NameserverEntry(const isc::dns::AbstractRRset* v4Set,
+        const isc::dns::AbstractRRset* v6Set, time_t curtime = 0);
+
+    /// \brief Virtual Destructor
+    virtual ~NameserverEntry()
+    {}
 
     /// \brief Return Address
     ///
@@ -134,7 +136,7 @@
     virtual void setAddressUnreachable(const IOAddress& address);
 
     /// \return Owner Name of RRset
-    virtual string getName() const {
+    virtual std::string getName() const {
         return name_;
     }
 
@@ -162,15 +164,16 @@
     /// criteria is met.
     class AddressSelection : public std::binary_function<short, AddressEntry, bool> {
     public:
-        result_type operator()(short family, const AddressEntry& entry) const {
-            bool result = ((family != 0) && (entry.getAddress().getFamily() != family));
-            return result;
+        bool operator()(short family, const AddressEntry& entry) const {
+            bool match = (entry.getAddress().getFamily() == family) ||
+                (family == 0);
+            return (! match);
         }
     };
 
 private:
     boost::mutex    mutex_;             ///< Mutex protecting this object
-    string          name_;              ///< Canonical name of the nameserver
+    std::string     name_;              ///< Canonical name of the nameserver
     uint16_t        classCode_;         ///< Class of the nameserver
     std::vector<AddressEntry> address_; ///< Set of V4/V6 addresses
     time_t          expiration_;        ///< Summary expiration time

Modified: branches/trac356/src/lib/nsas/nsas_types.h
==============================================================================
--- branches/trac356/src/lib/nsas/nsas_types.h (original)
+++ branches/trac356/src/lib/nsas/nsas_types.h Wed Oct 27 10:13:33 2010
@@ -26,7 +26,7 @@
 /// Defines a set of typedefs used within the Network Address Store.
 
 /// \brief Array of nameserver addresses
-typedef std::vector<ip::address>    NasAddress
+typedef std::vector<ip::address>    NsasAddress
 
 
 #endif // __NSAS_TYPES_H

Modified: branches/trac356/src/lib/nsas/zone_entry.h
==============================================================================
--- branches/trac356/src/lib/nsas/zone_entry.h (original)
+++ branches/trac356/src/lib/nsas/zone_entry.h Wed Oct 27 10:13:33 2010
@@ -17,12 +17,10 @@
 #ifndef __ZONE_ENTRY_H
 #define __ZONE_ENTRY_H
 
-
 #include <string>
+#include <vector>
 #include <boost/thread.h>
 #include <boost/shared_ptr.h>
-
-using namespace std;
 
 class NameserverEntry;
 
@@ -42,7 +40,7 @@
     ///
     /// Creates a zone entry object with an RRset representing the nameservers,
     /// plus possibly additional RRsets holding address information.
-    ZoneEntry(AbstractRRset* nsrrset, vector<AbstractRRSet*> additional);
+    ZoneEntry(AbstractRRset* nsrrset, const std::vector<AbstractRRSet*>& additional);
 
     /// \brief Lookup Address
     ///
@@ -54,13 +52,10 @@
 
 private:
     boost::mutex    mutex_;     ///< Mutex protecting this zone entry
-    string          name_;      ///< Canonical zone name
-    short           class_;     ///< Class code
-    vector<boost::shared_ptr<NameserverEntry> > nameserver_; ///< Nameservers
+    std::string     name_;      ///< Canonical zone name
+    short           classCode_; ///< Class code
+    std::vector<boost::shared_ptr<NameserverEntry> > nameservers_; ///< Nameservers
     time_t          expiry_;    ///< Expiry time of this entry
 };
  
-
-
-
 #endif // __ZONE_ENTRY_H




More information about the bind10-changes mailing list