rrset_entry.h 4.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

#ifndef __RRSET_ENTRY_H
#define __RRSET_ENTRY_H

18
#include <dns/rrset.h>
19
#include <dns/message.h>
20
#include <dns/rrttl.h>
21 22
#include <nsas/nsas_entry.h>
#include <nsas/fetchable.h>
23
#include "cache_entry_key.h"
24 25 26 27 28 29

using namespace isc::nsas;

namespace isc {
namespace cache {

30
/// \enum RRsetTrustLevel
31
/// For detail of RRset trustworthiness, please refer to
32
/// RFC 2181 section 5.4.1.
33 34
/// Bigger value is more trustworthy.
enum RRsetTrustLevel {
35
    /// Default trust for RRset.
36
    RRSET_TRUST_DEFAULT = 0,
37
    /// Additional information from non-authoritative answer.
38
    RRSET_TRUST_ADDITIONAL_NONAA,
39
    /// Data from the authority section of a non-authoritative answer
40
    RRSET_TRUST_AUTHORITY_NONAA,
41
    /// Additional information from an authoritative answer.
42
    RRSET_TRUST_ADDITIONAL_AA,
43 44
    /// Non-authoritative data from the answer section of authoritative
    /// answers
45
    RRSET_TRUST_NONAUTH_ANSWER_AA,
46
    /// Data from the answer section of a non-authoritative answer.
47
    RRSET_TRUST_ANSWER_NONAA,
48
    /// Glue from a primary zone, or glue from a zone transfer.
49
    RRSET_TRUST_PRIM_GLUE,
50
    /// Data from the authority section of an authoritative answer.
Ocean Wang's avatar
Ocean Wang committed
51
    RRSET_TRUST_AUTHORITY_AA,
52 53
    /// Authoritative data included in the answer section of
    /// an authoritative reply.
54
    RRSET_TRUST_ANSWER_AA,
55
    /// Data from a primary zone file, other than glue data.
56
    RRSET_TRUST_PRIM_ZONE_NONGLUE
57 58 59
};

/// \brief RRset Entry
60
/// The object of RRsetEntry represents one cached RRset.
Ocean Wang's avatar
Ocean Wang committed
61
/// Each RRset entry may be refered using shared_ptr by several message
62
/// entries.
63
class RRsetEntry : public NsasEntry<RRsetEntry>
64
{
65 66 67 68 69 70 71 72 73
    ///
    /// \name Constructors and Destructor
    ///
    /// Note: The copy constructor and the assignment operator are intentionally
    /// defined as private to make it uncopyable
    //@{
private:
    RRsetEntry(const RRsetEntry&);
    RRsetEntry& operator=(const RRsetEntry&);
74
public:
75 76 77
    /// \brief Constructor
    /// \param rrset The RRset used to initialize the RRset entry.
    /// \param level trustworthiness of the RRset.
78 79
    RRsetEntry(const isc::dns::AbstractRRset& rrset,
               const RRsetTrustLevel& level);
80

81 82 83 84
    /// The destructor.
    ~RRsetEntry() {}
    //@}

85
    /// \brief Return a pointer to a generated RRset
86 87
    ///
    /// \return Pointer to the generated RRset
88
    isc::dns::RRsetPtr getRRset();
Ocean Wang's avatar
Ocean Wang committed
89

90
    /// \brief Get the expiration time of the RRset.
91 92 93
    ///
    /// \return The expiration time of the RRset
    ///
94
    /// \todo RRsig expiration processing
95 96
    time_t getExpireTime() const;

97
    /// \brief Get the ttl of the RRset.
98 99
    ///
    /// \return The TTL of the RRset
100 101
    uint32_t getTTL() {
        updateTTL();
102
        return (rrset_->getTTL().getValue());
103
    }
104

105 106
    /// \brief Get the hash key
    ///
107
    /// \return return hash key
108
    HashKey hashKey() const {
109
        return (hash_key_);
110
    }
111

112
    /// \brief get RRset trustworthiness
113 114
    ///
    /// \return return the trust level
115
    RRsetTrustLevel getTrustLevel() const {
116
        return (trust_level_);
117
    }
118
private:
119 120
    /// \brief Update TTL according to expiration time
    void updateTTL();
121

122
private:
123 124 125
    std::string entry_name_; // The entry name for this rrset entry.
    time_t expire_time_;     // Expiration time of rrset.
    RRsetTrustLevel trust_level_; // RRset trustworthiness.
126
    boost::shared_ptr<isc::dns::RRset> rrset_;
127
    HashKey hash_key_;       // RRsetEntry hash key
128
};
Ocean Wang's avatar
Ocean Wang committed
129 130

typedef boost::shared_ptr<RRsetEntry> RRsetEntryPtr;
131

132 133 134 135 136
} // namespace cache
} // namespace isc

#endif // __RRSET_ENTRY_H