rrset_entry.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 <config.h>
  16. #include <dns/message.h>
  17. #include <nsas/nsas_entry.h>
  18. #include <nsas/fetchable.h>
  19. #include "rrset_entry.h"
  20. #include "rrset_copy.h"
  21. using namespace isc::dns;
  22. namespace isc {
  23. namespace cache {
  24. RRsetEntry::RRsetEntry(const isc::dns::RRset& rrset, const RRsetTrustLevel& level):
  25. entry_name_(genCacheEntryName(rrset.getName(), rrset.getType())),
  26. expire_time_(time(NULL) + rrset.getTTL().getValue()),
  27. trust_level_(level),
  28. rrset_(new RRset(rrset.getName(), rrset.getClass(), rrset.getType(), rrset.getTTL())),
  29. hash_key_(HashKey(entry_name_, rrset_->getClass()))
  30. {
  31. rrsetCopy(rrset, *(rrset_.get()));
  32. }
  33. isc::dns::RRsetPtr
  34. RRsetEntry::getRRset() {
  35. updateTTL();
  36. return (rrset_);
  37. }
  38. time_t
  39. RRsetEntry::getExpireTime() const {
  40. return (expire_time_);
  41. }
  42. void
  43. RRsetEntry::updateTTL(){
  44. uint32_t oldTTL = rrset_->getTTL().getValue();
  45. if(oldTTL == 0) {
  46. return;
  47. }
  48. uint32_t now = time(NULL);
  49. uint32_t newTTL = now < expire_time_ ? (expire_time_ - now) : 0;
  50. RRTTL ttl(newTTL);
  51. rrset_->setTTL(ttl);
  52. }
  53. } // namespace cache
  54. } // namespace isc