1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
// 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 __MESSAGE_CACHE_H
#define __MESSAGE_CACHE_H
#include <string>
#include <boost/shared_ptr.hpp>
#include <dns/message.h>
#include "message_entry.h"
#include <nsas/hash_table.h>
#include <nsas/lru_list.h>
#include "rrset_cache.h"
namespace isc {
namespace cache {
/// \brief Message Cache
/// The object of MessageCache represents the cache for class-specific
/// messages.
///
class MessageCache {
// Noncopyable
private:
MessageCache(const MessageCache& source);
MessageCache& operator=(const MessageCache& source);
public:
/// \param rrset_cache The cache that stores the RRsets that the
/// message entry will points to
/// \param cache_size The size of message cache.
/// \param message_class The class of the message cache
/// \param negative_soa_cache The cache that stores the SOA record
/// that comes from negative response message
MessageCache(const RRsetCachePtr& rrset_cache,
uint32_t cache_size, uint16_t message_class,
const RRsetCachePtr& negative_soa_cache);
/// \brief Destructor function
virtual ~MessageCache();
/// \brief Look up message in cache.
/// \param message generated response message if the message entry
/// can be found.
///
/// \return return true if the message can be found in cache, or else,
/// return false.
//TODO Maybe some user just want to get the message_entry.
bool lookup(const isc::dns::Name& qname,
const isc::dns::RRType& qtype,
isc::dns::Message& message);
/// \brief Update the message in the cache with the new one.
/// If the message doesn't exist in the cache, it will be added
/// directly.
bool update(const isc::dns::Message& msg);
#if 0
/// \brief Dump the message cache to specified file.
/// \todo It should can be dumped to one configured database.
void dump(const std::string& file_name);
/// \brief Load the cache from one file.
/// \todo It should can be loaded from one configured database.
void load(const std::string& file_name);
/// \brief Resize the size of message cache in runtime.
bool resize(uint32_t size);
#endif
protected:
/// \brief Get the hash key for the message entry in the cache.
/// \param name query name of the message.
/// \param type query type of the message.
/// \return return the hash key.
HashKey getEntryHashKey(const isc::dns::Name& name,
const isc::dns::RRType& type) const;
// Make these variants be protected for easy unittest.
protected:
uint16_t message_class_; // The class of the message cache.
RRsetCachePtr rrset_cache_;
RRsetCachePtr negative_soa_cache_;
isc::nsas::HashTable<MessageEntry> message_table_;
isc::nsas::LruList<MessageEntry> message_lru_;
};
typedef boost::shared_ptr<MessageCache> MessageCachePtr;
} // namespace cache
} // namespace isc
#endif // __MESSAGE_CACHE_H
|