message_cache.cc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. // $Id$
  15. #include <nsas/nsas_entry_compare.h>
  16. #include <nsas/hash_table.h>
  17. #include <nsas/hash_deleter.h>
  18. #include "message_cache.h"
  19. #include "cache_entry_key.h"
  20. using namespace isc::nsas;
  21. using namespace isc::dns;
  22. namespace isc {
  23. namespace cache {
  24. MessageCache::MessageCache(boost::shared_ptr<RRsetCache> rrset_cache,
  25. uint32_t cache_size, uint16_t message_class):
  26. message_class_(message_class),
  27. rrset_cache_(rrset_cache),
  28. message_table_(new NsasEntryCompare<MessageEntry>, cache_size),
  29. message_lru_((3 * cache_size),
  30. new HashDeleter<MessageEntry>(message_table_))
  31. {
  32. }
  33. bool
  34. MessageCache::lookup(const isc::dns::Name& qname,
  35. const isc::dns::RRType& qtype,
  36. const uint16_t query_header,
  37. isc::dns::Message& response)
  38. {
  39. std::pair<const char*, const uint32_t> keydata = genCacheEntryKey(qname, qtype);
  40. //TODO, HashKey need to be refactored, since we don't need query class
  41. // as the parameters.
  42. boost::shared_ptr<MessageEntry> msg_entry = message_table_.get(HashKey(
  43. keydata.first, keydata.second, RRClass(message_class_)));
  44. if(msg_entry) {
  45. return msg_entry->genMessage(time(NULL), query_header, response);
  46. }
  47. return false;
  48. }
  49. bool
  50. MessageCache::update(const Message&) {
  51. return true;
  52. }
  53. void
  54. MessageCache::dump(const std::string&) {
  55. }
  56. void
  57. MessageCache::load(const std::string&) {
  58. }
  59. bool
  60. MessageCache::resize(uint32_t) {
  61. return true;
  62. }
  63. } // namespace cache
  64. } // namespace isc