Commit 203152fa authored by Likun Zhang's avatar Likun Zhang
Browse files

Implement the interface MessageCache::Lookup.

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac449@4028 e5f2f494-b856-4b98-b285-d166d9295462
parent b6b9f884
......@@ -26,5 +26,6 @@ libcache_la_SOURCES += message_cache.h message_cache.cc
libcache_la_SOURCES += message_entry.h message_entry.cc
libcache_la_SOURCES += rrset_cache.h rrset_cache.cc
libcache_la_SOURCES += rrset_entry.h rrset_entry.cc
libcache_la_SOURCES += cache_entry_key.h
CLEANFILES = *.gcno *.gcda
// 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.
// $Id$
#ifndef __CACHE_ENTRY_H
#define __CACHE_ENTRY_H
#include <string>
namespace isc {
namespace cache {
class Name;
class RRtype;
std::pair<const char*, const uint32_t>
genCacheEntryKey(const isc::dns::Name& qname,
const isc::dns::RRType& qtype)
{
std::string keystr = qname.toText();
//TODO, use uint16_t rcode in case the text is too long?
keystr += qtype.toText();
return std::pair<const char*, const uint32_t>(keystr.c_str(), keystr.length());
}
} // namespace cache
} // namespace isc
#endif // __CACHE_ENTRY_H
......@@ -14,18 +14,21 @@
// $Id$
#include "message_cache.h"
#include <nsas/nsas_entry_compare.h>
#include <nsas/hash_table.h>
#include <nsas/hash_deleter.h>
#include "message_cache.h"
#include "cache_entry_key.h"
using namespace isc::nsas;
using namespace isc::dns;
namespace isc {
namespace cache {
MessageCache::MessageCache(boost::shared_ptr<RRsetCache> rrset_cache,
uint32_t cache_size):
uint32_t cache_size, uint16_t message_class):
message_class_(message_class),
rrset_cache_(rrset_cache),
message_table_(new NsasEntryCompare<MessageEntry>, cache_size),
message_lru_((3 * cache_size),
......@@ -35,16 +38,26 @@ MessageCache::MessageCache(boost::shared_ptr<RRsetCache> rrset_cache,
}
bool
MessageCache::lookUp(const isc::dns::Name&,
const isc::dns::RRType&,
const isc::dns::RRClass&,
isc::dns::Message& )
MessageCache::lookup(const isc::dns::Name& qname,
const isc::dns::RRType& qtype,
const uint16_t query_header,
isc::dns::Message& response)
{
return true;
std::pair<const char*, const uint32_t> keydata = genCacheEntryKey(qname, qtype);
//TODO, HashKey need to be refactored, since we don't need query class
// as the parameters.
boost::shared_ptr<MessageEntry> msg_entry = message_table_.get(HashKey(
keydata.first, keydata.second, RRClass(message_class_)));
if(msg_entry) {
return msg_entry->genMessage(time(NULL), query_header, response);
}
return false;
}
bool
MessageCache::update(const isc::dns::Message&) {
MessageCache::update(const Message&) {
return true;
}
......
......@@ -36,20 +36,23 @@ class RRsetCache;
///
class MessageCache {
public:
/// \param cache_size The size of message cache.
MessageCache(boost::shared_ptr<RRsetCache> rrset_cache_,
uint32_t cache_size);
uint32_t cache_size, uint16_t message_class);
/// \brief Look up message in cache.
/// \param message generated response message if the message entry
/// can be found.
/// \param query_header the uint16_t length header of the query message.
/// The message in the cache maybe need to be refactored when answering the
/// lookup according the query header(flags).
///
/// \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,
bool lookup(const isc::dns::Name& qname,
const isc::dns::RRType& qtype,
const isc::dns::RRClass& qclass,
const uint16_t query_header,
isc::dns::Message& message);
/// \brief Update the message in the cache with the new one.
......@@ -69,7 +72,7 @@ public:
bool resize(uint32_t size);
private:
uint16_t class_; // The class of the message cache.
uint16_t message_class_; // The class of the message cache.
boost::shared_ptr<RRsetCache> rrset_cache_;
isc::nsas::HashTable<MessageEntry> message_table_;
isc::nsas::LruList<MessageEntry> message_lru_;
......
......@@ -30,12 +30,12 @@ MessageEntry::MessageEntry(const isc::dns::Message&,
}
void
MessageEntry::generateMessage(const time_t&,
const uint16_t,
isc::dns::Message&)
bool
MessageEntry::genMessage(const time_t&,
const uint16_t,
isc::dns::Message&)
{
return true;
}
void
......
......@@ -31,6 +31,9 @@ namespace cache {
class RRsetEntry;
class RRsetCache;
/// \brief Message Entry
/// The object of MessageEntry represents one response message
/// answered to the recursor client.
class MessageEntry : public NsasEntry<MessageEntry>,
public Fetchable
{
......@@ -52,9 +55,11 @@ public:
/// as "expire_time - time_now" (expire_time is the
/// expiration time of the rrset).
/// \param query_header the query message header.
void generateMessage(const time_t& time_now,
const uint16_t query_header,
isc::dns::Message& response);
/// \return return true if the response message can be generated
/// from the cached information, or else, return false.
bool genMessage(const time_t& time_now,
const uint16_t query_header,
isc::dns::Message& response);
protected:
// Initialize the message entry with dns message.
void initMessageEntry(const isc::dns::Message& message);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment