Browse Source

Modifications as result of code review

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac356@3372 e5f2f494-b856-4b98-b285-d166d9295462
Stephen Morris 14 years ago
parent
commit
a90482b1de

+ 5 - 1
src/lib/nsas/hash.cc

@@ -63,6 +63,8 @@ if advised of the possibility of such damage.
 
 #include "hash.h"
 
+using namespace std;
+
 namespace isc {
 namespace nsas {
 
@@ -118,7 +120,9 @@ Hash::Hash(uint32_t tablesize, uint32_t maxkeylen, bool randomise) :
 }
 
 
-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;

+ 13 - 10
src/lib/nsas/hash.h

@@ -22,8 +22,6 @@
 
 #include "exceptions/exceptions.h"
 
-using namespace std;
-
 namespace isc {
 namespace nsas {
 
@@ -55,12 +53,16 @@ public:
     /// \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
     ///
     /// \return The hash table size with which this object was initialized
@@ -84,7 +86,8 @@ public:
     /// 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 @@ public:
     /// \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 @@ private:
 
     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

+ 0 - 1
src/lib/nsas/hash_table.h

@@ -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;

+ 6 - 2
src/lib/nsas/lru_list.h

@@ -105,6 +105,10 @@ public:
         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 @@ public:
     /// 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 @@ public:
     /// \brief Return Maximum Size
     ///
     /// \return Maximum size of the list
-    virtual uint32_t getMaxSize() {
+    virtual uint32_t getMaxSize() const {
         return max_size_;
     }
 

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

@@ -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 @@ namespace nsas {
 
 // 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 @@ void NameserverEntry::setAddressUnreachable(const IOAddress& address) {
     setAddressRTT(address, AddressEntry::UNREACHABLE);
 }
 
-
 } // namespace dns
 } // namespace isc

+ 13 - 10
src/lib/nsas/nameserver_entry.h

@@ -26,9 +26,6 @@
 #include "exceptions/exceptions.h"
 #include "rrset.h"
 
-using namespace std;
-using namespace isc::dns;
-
 namespace isc {
 namespace nsas {
 
@@ -82,7 +79,7 @@ public:
     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 @@ 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.
-    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 @@ public:
     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 @@ public:
     /// 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

+ 1 - 1
src/lib/nsas/nsas_types.h

@@ -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

+ 5 - 10
src/lib/nsas/zone_entry.h

@@ -17,13 +17,11 @@
 #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;
 
 /// \brief Zone Entry
@@ -42,7 +40,7 @@ public:
     ///
     /// 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 @@ public:
 
 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