reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
RRCache.hxx
Go to the documentation of this file.
1#ifndef RESIP_RRCACHE_HXX
2#define RESIP_RRCACHE_HXX
3
4#include <map>
5#include <set>
6#include <memory>
7
15#include "rutil/dns/RRList.hxx"
16
17namespace resip
18{
19class RROverlay;
20
22{
23 public:
27 typedef std::vector<RROverlay>::const_iterator Itr;
28 typedef std::vector<Data> DataArr;
29
30 RRCache();
31 ~RRCache();
32 void setTTL(int ttl) { if (ttl > 0) mUserDefinedTTL = ttl * MIN_TO_SEC; }
33 void setSize(int size) { mSize = size; }
34 // Update existing cache record, or add a new one
35 void updateCache(const Data& target,
36 const int rrType,
37 Itr begin,
38 Itr end);
40 // Called to update the cache when there are DNS server errors (ie. record not found)
41 void cacheTTL(const Data& target,
42 const int rrType,
43 const int status,
44 RROverlay overlay);
45 bool lookup(const Data& target, const int type, const int proto, Result& records, int& status);
46 void clearCache();
47 void logCache();
48 void getCacheDump(Data& dnsCacheDump);
49
50 private:
51 static const int MIN_TO_SEC = 60;
52 static const int DEFAULT_USER_DEFINED_TTL = 10; // in seconds.
53
54 static const int DEFAULT_SIZE = 512;
55 class CompareT
56 {
57 public:
58 bool operator()(const RRList* lhs, const RRList* rhs) const
59 {
60 if (lhs->rrType() < rhs->rrType())
61 {
62 return true;
63 }
64 else if (lhs->rrType() > rhs->rrType())
65 {
66 return false;
67 }
68 else
69 {
70 return (Data(lhs->key())).lowercase() < (Data(rhs->key())).lowercase();
71 }
72 }
73 };
74
75 void touch(RRList* node);
76 void cleanup();
77 int getTTL(const RROverlay& overlay);
78 void purge();
79
80 RRList mHead;
81 LruListType* mLruHead;
82 Result Empty;
83
84 typedef std::set<RRList*, CompareT> RRSet;
85 RRSet mRRSet;
86
87 RRFactory<DnsHostRecord> mHostRecordFactory;
88 RRFactory<DnsSrvRecord> mSrvRecordFactory;
89 RRFactory<DnsAAAARecord> mAAAARecordFactory;
90 RRFactory<DnsNaptrRecord> mNaptrRecordFacotry;
91 RRFactory<DnsCnameRecord> mCnameRecordFactory;
92
93 typedef std::map<int, resip::RRFactoryBase*> FactoryMap;
94 FactoryMap mFactoryMap;
95
96 int mUserDefinedTTL; // used when the ttl in RR is 0 or less than default(10). in seconds.
97 unsigned int mSize;
98};
99
100}
101
102#endif
103
104
105/* ====================================================================
106 * The Vovida Software License, Version 1.0
107 *
108 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
109 * Copyright (c) 2010 SIP Spectrum, Inc. All rights reserved.
110 *
111 * Redistribution and use in source and binary forms, with or without
112 * modification, are permitted provided that the following conditions
113 * are met:
114 *
115 * 1. Redistributions of source code must retain the above copyright
116 * notice, this list of conditions and the following disclaimer.
117 *
118 * 2. Redistributions in binary form must reproduce the above copyright
119 * notice, this list of conditions and the following disclaimer in
120 * the documentation and/or other materials provided with the
121 * distribution.
122 *
123 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
124 * and "Vovida Open Communication Application Library (VOCAL)" must
125 * not be used to endorse or promote products derived from this
126 * software without prior written permission. For written
127 * permission, please contact vocal@vovida.org.
128 *
129 * 4. Products derived from this software may not be called "VOCAL", nor
130 * may "VOCAL" appear in their name, without prior written
131 * permission of Vovida Networks, Inc.
132 *
133 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
134 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
135 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
136 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
137 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
138 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
139 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
140 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
141 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
142 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
144 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
145 * DAMAGE.
146 *
147 * ====================================================================
148 *
149 * This software consists of voluntary contributions made by Vovida
150 * Networks, Inc. and many individuals on behalf of Vovida Networks,
151 * Inc. For more information on Vovida Networks, Inc., please see
152 * <http://www.vovida.org/>.
153 *
154 */
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
void setSize(int size)
Definition RRCache.hxx:33
RRList::Protocol Protocol
Definition RRCache.hxx:24
std::vector< Data > DataArr
Definition RRCache.hxx:28
void updateCacheFromHostFile(const DnsHostRecord &)
Definition RRCache.cxx:76
bool lookup(const Data &target, const int type, const int proto, Result &records, int &status)
Definition RRCache.cxx:199
RRList::LruList LruListType
Definition RRCache.hxx:25
void setTTL(int ttl)
Definition RRCache.hxx:32
std::vector< RROverlay >::const_iterator Itr
Definition RRCache.hxx:27
void cacheTTL(const Data &target, const int rrType, const int status, RROverlay overlay)
Definition RRCache.cxx:164
void updateCache(const Data &target, const int rrType, Itr begin, Itr end)
Definition RRCache.cxx:104
void getCacheDump(Data &dnsCacheDump)
Definition RRCache.cxx:326
RRList::Records Result
Definition RRCache.hxx:26
void logCache()
Definition RRCache.cxx:318
void clearCache()
Definition RRCache.cxx:243
int rrType() const
Definition RRList.hxx:53
const Data & key() const
Definition RRList.hxx:51
std::vector< DnsResourceRecord * > Records
Definition RRList.hxx:28
dcm! – add UnusedChecking(_enum) below;