LCOV - code coverage report
Current view: top level - nsas - nameserver_address_store.cc (source / functions) Hit Total Coverage
Test: report.info Lines: 17 25 68.0 %
Date: 2012-05-15 Functions: 4 5 80.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 17 38 44.7 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
       2                 :            : //
       3                 :            : // Permission to use, copy, modify, and/or distribute this software for any
       4                 :            : // purpose with or without fee is hereby granted, provided that the above
       5                 :            : // copyright notice and this permission notice appear in all copies.
       6                 :            : //
       7                 :            : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
       8                 :            : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
       9                 :            : // AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
      10                 :            : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
      11                 :            : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
      12                 :            : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
      13                 :            : // PERFORMANCE OF THIS SOFTWARE.
      14                 :            : 
      15                 :            : #include <config.h>
      16                 :            : 
      17                 :            : #include <boost/shared_ptr.hpp>
      18                 :            : #include <boost/foreach.hpp>
      19                 :            : #include <boost/bind.hpp>
      20                 :            : 
      21                 :            : #include <config.h>
      22                 :            : #include <dns/rdataclass.h>
      23                 :            : #include <util/locks.h>
      24                 :            : #include <util/lru_list.h>
      25                 :            : #include <log/logger.h>
      26                 :            : 
      27                 :            : #include "hash_table.h"
      28                 :            : #include "hash_deleter.h"
      29                 :            : #include "nsas_entry_compare.h"
      30                 :            : #include "nameserver_entry.h"
      31                 :            : #include "nameserver_address_store.h"
      32                 :            : #include "zone_entry.h"
      33                 :            : #include "glue_hints.h"
      34                 :            : #include "address_request_callback.h"
      35                 :            : #include "nsas_log.h"
      36                 :            : 
      37                 :            : using namespace isc::dns;
      38                 :            : using namespace std;
      39                 :            : 
      40                 :            : namespace isc {
      41                 :            : namespace nsas {
      42                 :            : 
      43                 :            : // Constructor.
      44                 :            : //
      45                 :            : // The LRU lists are set equal to three times the size of the respective
      46                 :            : // hash table, on the assumption that three elements is the longest linear
      47                 :            : // search we want to do when looking up names in the hash table.
      48                 :         30 : NameserverAddressStore::NameserverAddressStore(
      49                 :            :     boost::shared_ptr<isc::resolve::ResolverInterface> resolver,
      50                 :            :     uint32_t zonehashsize, uint32_t nshashsize) :
      51                 :            :     zone_hash_(new HashTable<ZoneEntry>(new NsasEntryCompare<ZoneEntry>,
      52         [ +  - ]:         30 :         zonehashsize)),
      53                 :            :     nameserver_hash_(new HashTable<NameserverEntry>(
      54         [ +  - ]:         30 :         new NsasEntryCompare<NameserverEntry>, nshashsize)),
      55                 :            :     zone_lru_(new isc::util::LruList<ZoneEntry>((3 * zonehashsize),
      56                 :          0 :         new HashDeleter<ZoneEntry>(*zone_hash_))),
      57                 :            :     nameserver_lru_(new isc::util::LruList<NameserverEntry>((3 * nshashsize),
      58                 :          0 :         new HashDeleter<NameserverEntry>(*nameserver_hash_))),
      59 [ +  - ][ +  - ]:        120 :     resolver_(resolver.get())
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      60                 :         30 : { }
      61                 :            : 
      62                 :            : namespace {
      63                 :            : 
      64                 :            : /*
      65                 :            :  * We use pointers here so there's no call to any copy constructor.
      66                 :            :  * It is easier for the compiler to inline it and prove that there's
      67                 :            :  * no need to copy anything. In that case, the bind should not be
      68                 :            :  * called at all to create the object, just call the function.
      69                 :            :  */
      70                 :            : boost::shared_ptr<ZoneEntry>
      71                 :         13 : newZone(
      72                 :            :     isc::resolve::ResolverInterface* resolver,
      73                 :            :     const string* zone, const RRClass* class_code,
      74                 :            :     const boost::shared_ptr<HashTable<NameserverEntry> >* ns_hash,
      75                 :            :     const boost::shared_ptr<isc::util::LruList<NameserverEntry> >* ns_lru)
      76                 :            : {
      77                 :            :     boost::shared_ptr<ZoneEntry> result(new ZoneEntry(resolver, *zone, *class_code,
      78 [ +  - ][ +  - ]:         13 :         *ns_hash, *ns_lru));
                 [ +  - ]
      79                 :         13 :     return (result);
      80                 :            : }
      81                 :            : 
      82                 :            : }
      83                 :            : 
      84                 :            : void
      85                 :       2017 : NameserverAddressStore::lookup(const string& zone, const RRClass& class_code,
      86                 :            :     boost::shared_ptr<AddressRequestCallback> callback, AddressFamily family,
      87                 :            :     const GlueHints& glue_hints)
      88                 :            : {
      89         [ +  - ]:       4034 :     LOG_DEBUG(nsas_logger, NSAS_DBG_TRACE, NSAS_SEARCH_ZONE_NS).arg(zone);
      90                 :            : 
      91                 :            :     pair<bool, boost::shared_ptr<ZoneEntry> > zone_obj(
      92                 :            :         zone_hash_->getOrAdd(HashKey(zone, class_code),
      93                 :            :                              boost::bind(newZone, resolver_, &zone, &class_code,
      94                 :       2017 :                                          &nameserver_hash_, &nameserver_lru_)));
      95         [ +  + ]:       2017 :     if (zone_obj.first) {
      96         [ +  - ]:         13 :         zone_lru_->add(zone_obj.second);
      97                 :            :     } else {
      98         [ +  - ]:       2004 :         zone_lru_->touch(zone_obj.second);
      99                 :            :     }
     100                 :            :     
     101         [ +  - ]:       2017 :     zone_obj.second->addCallback(callback, family, glue_hints);
     102                 :       2017 : }
     103                 :            : 
     104                 :            : void
     105                 :          0 : NameserverAddressStore::cancel(const string& zone,
     106                 :            :     const RRClass& class_code,
     107                 :            :     const boost::shared_ptr<AddressRequestCallback>& callback,
     108                 :            :     AddressFamily family)
     109                 :            : {
     110         [ #  # ]:          0 :     LOG_DEBUG(nsas_logger, NSAS_DBG_TRACE, NSAS_LOOKUP_CANCEL).arg(zone);
     111                 :            : 
     112                 :            :     boost::shared_ptr<ZoneEntry> entry(zone_hash_->get(HashKey(zone,
     113                 :          0 :                                                                class_code)));
     114         [ #  # ]:          0 :     if (entry) {
     115         [ #  # ]:          0 :         entry->removeCallback(callback, family);
     116                 :            :     }
     117                 :          0 : }
     118                 :            : 
     119                 :            : } // namespace nsas
     120                 :          4 : } // namespace isc

Generated by: LCOV version 1.9