Branch data Line data Source code
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 : :
15 : : #include <config.h>
16 : :
17 : : #include <dns/message.h>
18 : : #include <nsas/nsas_entry.h>
19 : : #include <nsas/fetchable.h>
20 : : #include "rrset_entry.h"
21 : : #include "rrset_copy.h"
22 : :
23 : : using namespace isc::dns;
24 : :
25 : : namespace isc {
26 : : namespace cache {
27 : :
28 : 173 : RRsetEntry::RRsetEntry(const isc::dns::AbstractRRset& rrset,
29 : : const RRsetTrustLevel& level):
30 [ + - ][ + - ]: 173 : entry_name_(genCacheEntryName(rrset.getName(), rrset.getType())),
31 [ + - ]: 173 : expire_time_(time(NULL) + rrset.getTTL().getValue()),
32 : : trust_level_(level),
33 [ + - ]: 173 : rrset_(new RRset(rrset.getName(), rrset.getClass(), rrset.getType(), rrset.getTTL())),
34 [ + - ][ + - ]: 519 : hash_key_(HashKey(entry_name_, rrset_->getClass()))
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
35 : : {
36 [ + - ]: 173 : rrsetCopy(rrset, *(rrset_.get()));
37 : 173 : }
38 : :
39 : : isc::dns::RRsetPtr
40 : 72 : RRsetEntry::getRRset() {
41 : 72 : updateTTL();
42 : 72 : return (rrset_);
43 : : }
44 : :
45 : : time_t
46 : 167 : RRsetEntry::getExpireTime() const {
47 : 167 : return (expire_time_);
48 : : }
49 : :
50 : : void
51 : 233 : RRsetEntry::updateTTL(){
52 : 233 : uint32_t oldTTL = rrset_->getTTL().getValue();
53 [ + + ]: 233 : if(oldTTL == 0) {
54 : 233 : return;
55 : : }
56 : :
57 : 231 : uint32_t now = time(NULL);
58 [ + + ]: 231 : uint32_t newTTL = now < expire_time_ ? (expire_time_ - now) : 0;
59 : :
60 : : RRTTL ttl(newTTL);
61 : 231 : rrset_->setTTL(ttl);
62 : : }
63 : :
64 : : } // namespace cache
65 : 3 : } // namespace isc
66 : :
67 : :
|