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 : : #ifndef __NAMESERVER_ADDRESS_STORE_H
16 : : #define __NAMESERVER_ADDRESS_STORE_H
17 : :
18 : : #include <string>
19 : : #include <vector>
20 : :
21 : : #include <boost/shared_ptr.hpp>
22 : :
23 : : #include <resolve/resolver_interface.h>
24 : :
25 : : #include "nsas_types.h"
26 : : #include "glue_hints.h"
27 : :
28 : : namespace isc {
29 : : // Some forward declarations, so we do not need to include so many headers
30 : :
31 : : namespace dns {
32 : : class RRClass;
33 : : }
34 : :
35 : : namespace util {
36 : : template<class T> class LruList;
37 : : }
38 : :
39 : : namespace nsas {
40 : :
41 : : template<class T> class HashTable;
42 : : class ZoneEntry;
43 : : class NameserverEntry;
44 : : class AddressRequestCallback;
45 : :
46 : : /// \brief Nameserver Address Store
47 : : ///
48 : : /// This class implements the bare bones of the nameserver address store - the
49 : : /// storage of nameserver information. An additional layer above it implements
50 : : /// the logic for sending queries for the nameserver addresses if they are not
51 : : /// in the store.
52 : :
53 : : class NameserverAddressStore {
54 : : public:
55 : :
56 : : /// \brief Constructor
57 : : ///
58 : : /// The constructor sizes all the tables. As there are various
59 : : /// relationships between the table sizes, and as some values are best as
60 : : /// prime numbers, the table sizes are determined by compile-time values.
61 : : ///
62 : : /// \param resolver Which resolver object (or resolver-like, in case of
63 : : /// tests) should it use to ask questions.
64 : : /// \param zonehashsize Size of the zone hash table. The default value of
65 : : /// 1009 is the first prime number above 1000.
66 : : /// \param nshashsize Size of the nameserver hash table. The default
67 : : /// value of 3001 is the first prime number over 3000, and by implication,
68 : : /// there is an assumption that there will be more nameservers than zones
69 : : /// in the store.
70 : : NameserverAddressStore(
71 : : boost::shared_ptr<isc::resolve::ResolverInterface> resolver,
72 : : uint32_t zonehashsize = 1009, uint32_t nshashsize = 3001);
73 : :
74 : : /// \brief Destructor
75 : : ///
76 : : /// Empty virtual destructor.
77 : 49 : virtual ~NameserverAddressStore()
78 : 49 : {}
79 : :
80 : : /// \brief Lookup Address for a Zone
81 : : ///
82 : : /// Looks up the address of a nameserver in the zone.
83 : : ///
84 : : /// \param zone Name of zone for which an address is required.
85 : : /// \param class_code Class of the zone.
86 : : /// \param callback Callback object used to pass the result back to the
87 : : /// caller.
88 : : /// \param family Which address is requested.
89 : : void lookup(const std::string& zone, const dns::RRClass& class_code,
90 : : boost::shared_ptr<AddressRequestCallback> callback, AddressFamily
91 : : family = ANY_OK, const GlueHints& = GlueHints());
92 : :
93 : : /// \brief cancel the given lookup action
94 : : ///
95 : : /// \param zone Name of zone.
96 : : /// \param class_code Class of the zone.
97 : : /// \param callback Callback object that would be called.
98 : : /// \param family Address family for which lookup is being cancelled.
99 : : void cancel(const std::string& zone, const dns::RRClass& class_code,
100 : : const boost::shared_ptr<AddressRequestCallback>& callback,
101 : : AddressFamily family = ANY_OK);
102 : :
103 : : /// \brief Protected Members
104 : : ///
105 : : /// These members should be private. However, with so few public methods
106 : : /// and with a lot of internal processing, the testing of this class is
107 : : /// problematical.
108 : : ///
109 : : /// To get round this, a number of elements are declared protected. This
110 : : /// means that tests can be carried out by testing a subclass. The subclass
111 : : /// does not override the main class methods, but does contain additional
112 : : /// methods to set up data and examine the internal state of the class.
113 : : //@{
114 : : protected:
115 : : // Zone and nameserver hash tables
116 : : boost::shared_ptr<HashTable<ZoneEntry> > zone_hash_;
117 : : boost::shared_ptr<HashTable<NameserverEntry> > nameserver_hash_;
118 : :
119 : : // ... and the LRU lists
120 : : boost::shared_ptr<isc::util::LruList<ZoneEntry> > zone_lru_;
121 : : boost::shared_ptr<isc::util::LruList<NameserverEntry> > nameserver_lru_;
122 : : // The resolver we use
123 : : private:
124 : : isc::resolve::ResolverInterface* resolver_;
125 : : //}@
126 : : };
127 : :
128 : : } // namespace nsas
129 : : } // namespace isc
130 : :
131 : :
132 : : #endif // __NAMESERVER_ADDRESS_STORE_H
|