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_H
16 : : #define __NAMESERVER_ADDRESS_H
17 : :
18 : : #include <boost/shared_ptr.hpp>
19 : :
20 : : #include <exceptions/exceptions.h>
21 : :
22 : : #include "asiolink.h"
23 : : #include "address_entry.h"
24 : : #include "nsas_types.h"
25 : :
26 : : namespace isc {
27 : : namespace nsas {
28 : :
29 : : class ZoneEntry;
30 : : class NameserverEntry;
31 : :
32 : : /// \brief Empty \c NameserverEntry pointer exception
33 : : ///
34 : : /// Thrown if the the \c NameservrEntry pointer in the \c boost::shared_ptr that passed
35 : : /// into \c NameserverAddress' constructor is NULL
36 : 1 : class NullNameserverEntryPointer : public isc::Exception {
37 : : public:
38 : : NullNameserverEntryPointer(const char* file, size_t line,
39 : : const char* what) :
40 [ + - ]: 1 : isc::Exception(file, line, what)
41 : : {}
42 : : };
43 : :
44 : : /// \brief Nameserver Address
45 : : ///
46 : : /// This class implements the object that returned from NSAS when the resolver
47 : : /// request an address for the name server. It contains one address
48 : : /// that can be used by resolver. When the resolver get query back from the name
49 : : /// server, it should update the name server's RTT(Round Trip Time) with this
50 : : /// object.
51 : : ///
52 : : /// It is not thread safe, only reentrant. It is expected to be kept inside
53 : : /// the resolver and used only once for the address and once for the update.
54 : :
55 [ # # ][ # # ]: 4141423 : class NameserverAddress {
56 : : public:
57 : : /// \brief Constructor
58 : : ///
59 : : /// The NameserverAddress object will contain one shared_ptr object that
60 : : /// pointed to NameserverEntry which contains the address as well as it's
61 : : /// corresponding index. The user can update it's RTT with the index later.
62 : : ///
63 : : /// \param nameserver A shared_ptr that points to a NameserverEntry object
64 : : /// the shared_ptr can avoid the NameserverEntry object being dropped while the
65 : : /// request is processing.
66 : : /// \param address The address's index in NameserverEntry's addresses vector
67 : : /// \param family Address family, V4_ONLY or V6_ONLY
68 : 1204111 : NameserverAddress(const boost::shared_ptr<NameserverEntry>& nameserver,
69 : : const AddressEntry& address, AddressFamily family):
70 : 3612346 : ns_(nameserver), address_(address), family_(family)
71 : : {
72 [ + + ]: 1204115 : if(!ns_) {
73 [ + - ][ + - ]: 2 : isc_throw(NullNameserverEntryPointer, "NULL NameserverEntry pointer.");
74 : : }
75 : 1204110 : }
76 : :
77 : : /// \brief Default Constructor
78 [ + - ][ + - ]: 8 : NameserverAddress() : address_(asiolink::IOAddress("::1")) { }
79 : :
80 : : /// \brief Return address
81 : : ///
82 : : asiolink::IOAddress getAddress() const {
83 : 400054 : return (address_.getAddress());
84 : : }
85 : :
86 : : /// \brief Update Round-trip Time
87 : : ///
88 : : /// When the user get one request back from the name server, it should
89 : : /// update the address's RTT.
90 : : /// \param rtt The new Round-Trip Time
91 : : void updateRTT(uint32_t rtt) const;
92 : :
93 : : /// Short access to the AddressEntry inside.
94 : : //@{
95 : : const AddressEntry& getAddressEntry() const {
96 : : return (address_);
97 : : }
98 : : AddressEntry& getAddressEntry() {
99 : : return (address_);
100 : : }
101 : : //@}
102 : : private:
103 : :
104 : : /*
105 : : * Note: Previous implementation used index into the entry. That is wrong,
106 : : * as the list of addresses may change. Thil would cause setting a
107 : : * different address or a crash.
108 : : */
109 : : boost::shared_ptr<NameserverEntry> ns_; ///< Shared-pointer to NameserverEntry object
110 : : AddressEntry address_; ///< The address
111 : : AddressFamily family_; ///< The address family (V4_ONLY or V6_ONLY)
112 : : };
113 : :
114 : : } // namespace nsas
115 : : } // namespace isc
116 : :
117 : : #endif//__NAMESERVER_ADDRESS_H
|