|
reSIProcate/rutil
9694
|
#include <RRCache.hxx>

Classes | |
| class | CompareT |
Public Types | |
| typedef RRList::Protocol | Protocol |
| typedef RRList::LruList | LruListType |
| typedef RRList::Records | Result |
| typedef std::vector< RROverlay > ::const_iterator | Itr |
| typedef std::vector< Data > | DataArr |
Public Member Functions | |
| RRCache () | |
| ~RRCache () | |
| void | setTTL (int ttl) |
| void | setSize (int size) |
| void | updateCache (const Data &target, const int rrType, Itr begin, Itr end) |
| void | updateCacheFromHostFile (const DnsHostRecord &) |
| void | cacheTTL (const Data &target, const int rrType, const int status, RROverlay overlay) |
| bool | lookup (const Data &target, const int type, const int proto, Result &records, int &status) |
| void | clearCache () |
| void | logCache () |
| void | getCacheDump (Data &dnsCacheDump) |
Private Types | |
| typedef std::set< RRList *, CompareT > | RRSet |
| typedef std::map< int, resip::RRFactoryBase * > | FactoryMap |
Private Member Functions | |
| void | touch (RRList *node) |
| void | cleanup () |
| int | getTTL (const RROverlay &overlay) |
| void | purge () |
Private Attributes | |
| RRList | mHead |
| LruListType * | mLruHead |
| Result | Empty |
| RRSet | mRRSet |
| RRFactory< DnsHostRecord > | mHostRecordFactory |
| RRFactory< DnsSrvRecord > | mSrvRecordFactory |
| RRFactory< DnsAAAARecord > | mAAAARecordFactory |
| RRFactory< DnsNaptrRecord > | mNaptrRecordFacotry |
| RRFactory< DnsCnameRecord > | mCnameRecordFactory |
| FactoryMap | mFactoryMap |
| int | mUserDefinedTTL |
| unsigned int | mSize |
Static Private Attributes | |
| static const int | MIN_TO_SEC = 60 |
| static const int | DEFAULT_USER_DEFINED_TTL = 10 |
| static const int | DEFAULT_SIZE = 512 |
Definition at line 21 of file RRCache.hxx.
| typedef std::vector<Data> resip::RRCache::DataArr |
Definition at line 28 of file RRCache.hxx.
typedef std::map<int, resip::RRFactoryBase*> resip::RRCache::FactoryMap [private] |
Definition at line 93 of file RRCache.hxx.
| typedef std::vector<RROverlay>::const_iterator resip::RRCache::Itr |
Definition at line 27 of file RRCache.hxx.
Definition at line 25 of file RRCache.hxx.
Definition at line 24 of file RRCache.hxx.
Definition at line 26 of file RRCache.hxx.
typedef std::set<RRList*, CompareT> resip::RRCache::RRSet [private] |
Definition at line 84 of file RRCache.hxx.
| RRCache::RRCache | ( | ) |
Definition at line 49 of file RRCache.cxx.
References mAAAARecordFactory, mCnameRecordFactory, mFactoryMap, mHostRecordFactory, mNaptrRecordFacotry, mSrvRecordFactory, T_A, T_AAAA, T_NAPTR, and T_SRV.
: mHead(), mLruHead(LruListType::makeList(&mHead)), mUserDefinedTTL(DEFAULT_USER_DEFINED_TTL), mSize(DEFAULT_SIZE) { mFactoryMap[T_CNAME] = &mCnameRecordFactory; mFactoryMap[T_NAPTR] = &mNaptrRecordFacotry; mFactoryMap[T_SRV] = &mSrvRecordFactory; #ifdef USE_IPV6 mFactoryMap[T_AAAA] = &mAAAARecordFactory; #endif mFactoryMap[T_A] = &mHostRecordFactory; }
| RRCache::~RRCache | ( | ) |
Definition at line 64 of file RRCache.cxx.
References cleanup().
{
cleanup();
}

| void RRCache::cacheTTL | ( | const Data & | target, |
| const int | rrType, | ||
| const int | status, | ||
| RROverlay | overlay | ||
| ) |
Definition at line 119 of file RRCache.cxx.
References getTTL(), mLruHead, mRRSet, mUserDefinedTTL, purge(), and resip::IntrusiveListElement< P >::push_back().
Referenced by resip::DnsStub::cacheTTL().
{
int ttl = getTTL(overlay);
if (ttl < 0)
{
return;
}
if (ttl < mUserDefinedTTL)
{
ttl = mUserDefinedTTL;
}
RRList* val = new RRList(target, rrType, ttl, status);
RRSet::iterator it = mRRSet.find(val);
if (it != mRRSet.end())
{
(*it)->remove();
delete *it;
mRRSet.erase(it);
}
mRRSet.insert(val);
mLruHead->push_back(val);
purge();
}

| void RRCache::cleanup | ( | ) | [private] |
Definition at line 197 of file RRCache.cxx.
References mRRSet.
Referenced by clearCache(), and ~RRCache().
| void RRCache::clearCache | ( | ) |
Definition at line 184 of file RRCache.cxx.
References cleanup().
Referenced by resip::DnsStub::doClearDnsCache().
{
cleanup();
}

| void RRCache::getCacheDump | ( | Data & | dnsCacheDump | ) |
Definition at line 248 of file RRCache.cxx.
References mRRSet.
Referenced by resip::DnsStub::doGetDnsCacheDump().
{
DataStream strm(dnsCacheDump);
for (std::set<RRList*, CompareT>::iterator it = mRRSet.begin(); it != mRRSet.end(); it++)
{
(*it)->encodeRRList(strm);
}
strm.flush();
}
| int RRCache::getTTL | ( | const RROverlay & | overlay | ) | [private] |
Definition at line 208 of file RRCache.cxx.
References resip::RROverlay::data(), resip::RROverlay::msg(), resip::RROverlay::msgLength(), and resip::RROverlay::type().
Referenced by cacheTTL().
{
// overlay is a soa answer.
if (overlay.type() != T_SOA) return -1;
char* name = 0;
long len = 0;
int status = ares_expand_name(overlay.data(), overlay.msg(), overlay.msgLength(), &name, &len);
assert( status == ARES_SUCCESS );
const unsigned char* pPos = overlay.data() + len;
free(name); name = 0;
status = ares_expand_name(pPos, overlay.msg(), overlay.msgLength(), &name, &len);
assert( status == ARES_SUCCESS );
free(name);
pPos += len;
pPos += 16; // skip four 32 bit entities.
return DNS__32BIT(pPos);
}

| void RRCache::logCache | ( | ) |
Definition at line 239 of file RRCache.cxx.
References mRRSet.
Referenced by resip::DnsStub::doLogDnsCache().
| bool RRCache::lookup | ( | const Data & | target, |
| const int | type, | ||
| const int | proto, | ||
| Result & | records, | ||
| int & | status | ||
| ) |
Definition at line 150 of file RRCache.cxx.
References resip::Timer::getTimeSecs(), mRRSet, and touch().
{
records.empty();
status = 0;
RRList* key = new RRList(target, type);
RRSet::iterator it = mRRSet.find(key);
delete key;
if (it == mRRSet.end())
{
return false;
}
else
{
if (Timer::getTimeSecs() >= (*it)->absoluteExpiry())
{
delete *it;
mRRSet.erase(it);
return false;
}
else
{
records = (*it)->records(protocol);
status = (*it)->status();
touch(*it);
return true;
}
}
}

| void RRCache::purge | ( | ) | [private] |
Definition at line 227 of file RRCache.cxx.
References resip::IntrusiveListElement< P >::begin(), mLruHead, mRRSet, mSize, and resip::IntrusiveListElement< P >::remove().
Referenced by cacheTTL(), updateCache(), and updateCacheFromHostFile().
{
if (mRRSet.size() < mSize) return;
RRList* lst = *(mLruHead->begin());
RRSet::iterator it = mRRSet.find(lst);
assert(it != mRRSet.end());
lst->remove();
delete *it;
mRRSet.erase(it);
}

| void resip::RRCache::setSize | ( | int | size | ) | [inline] |
Definition at line 33 of file RRCache.hxx.
References mSize.
Referenced by resip::DnsStub::setDnsCacheSize().
{ mSize = size; }
| void resip::RRCache::setTTL | ( | int | ttl | ) | [inline] |
Definition at line 32 of file RRCache.hxx.
References MIN_TO_SEC, and mUserDefinedTTL.
Referenced by resip::DnsStub::setDnsCacheTTL().
{ if (ttl > 0) mUserDefinedTTL = ttl * MIN_TO_SEC; }
| void RRCache::touch | ( | RRList * | node | ) | [private] |
Definition at line 190 of file RRCache.cxx.
References mLruHead, resip::IntrusiveListElement< P >::push_back(), and resip::IntrusiveListElement< P >::remove().
Referenced by lookup(), updateCache(), and updateCacheFromHostFile().

Definition at line 92 of file RRCache.cxx.
References mFactoryMap, mLruHead, mRRSet, mUserDefinedTTL, purge(), resip::IntrusiveListElement< P >::push_back(), and touch().
Referenced by resip::DnsStub::cache().
{
Data domain = (*begin).domain();
FactoryMap::iterator it = mFactoryMap.find(rrType);
assert(it != mFactoryMap.end());
RRList* key = new RRList(domain, rrType);
RRSet::iterator lb = mRRSet.lower_bound(key);
if (lb != mRRSet.end() &&
!(mRRSet.key_comp()(key, *lb)))
{
(*lb)->update(it->second, begin, end, mUserDefinedTTL);
touch(*lb);
}
else
{
RRList* val = new RRList(it->second, domain, rrType, begin, end, mUserDefinedTTL);
mRRSet.insert(val);
mLruHead->push_back(val);
purge();
}
delete key;
}

| void RRCache::updateCacheFromHostFile | ( | const DnsHostRecord & | record | ) |
Definition at line 70 of file RRCache.cxx.
References mLruHead, mRRSet, purge(), resip::IntrusiveListElement< P >::push_back(), and touch().
Referenced by resip::DnsStub::cache().
{
//FactoryMap::iterator it = mFactoryMap.find(T_A);
RRList* key = new RRList(record, 3600);
RRSet::iterator lb = mRRSet.lower_bound(key);
if (lb != mRRSet.end() &&
!(mRRSet.key_comp()(key, *lb)))
{
(*lb)->update(record, 3600);
touch(*lb);
}
else
{
RRList* val = new RRList(record, 3600);
mRRSet.insert(val);
mLruHead->push_back(val);
purge();
}
delete key;
}

const int resip::RRCache::DEFAULT_SIZE = 512 [static, private] |
Definition at line 54 of file RRCache.hxx.
const int resip::RRCache::DEFAULT_USER_DEFINED_TTL = 10 [static, private] |
Definition at line 52 of file RRCache.hxx.
Result resip::RRCache::Empty [private] |
Definition at line 82 of file RRCache.hxx.
Definition at line 89 of file RRCache.hxx.
Referenced by RRCache().
Definition at line 91 of file RRCache.hxx.
Referenced by RRCache().
FactoryMap resip::RRCache::mFactoryMap [private] |
Definition at line 94 of file RRCache.hxx.
Referenced by RRCache(), and updateCache().
RRList resip::RRCache::mHead [private] |
Definition at line 80 of file RRCache.hxx.
Definition at line 87 of file RRCache.hxx.
Referenced by RRCache().
const int resip::RRCache::MIN_TO_SEC = 60 [static, private] |
Definition at line 51 of file RRCache.hxx.
Referenced by setTTL().
LruListType* resip::RRCache::mLruHead [private] |
Definition at line 81 of file RRCache.hxx.
Referenced by cacheTTL(), purge(), touch(), updateCache(), and updateCacheFromHostFile().
Definition at line 90 of file RRCache.hxx.
Referenced by RRCache().
RRSet resip::RRCache::mRRSet [private] |
Definition at line 85 of file RRCache.hxx.
Referenced by cacheTTL(), cleanup(), getCacheDump(), logCache(), lookup(), purge(), updateCache(), and updateCacheFromHostFile().
unsigned int resip::RRCache::mSize [private] |
Definition at line 97 of file RRCache.hxx.
Definition at line 88 of file RRCache.hxx.
Referenced by RRCache().
int resip::RRCache::mUserDefinedTTL [private] |
Definition at line 96 of file RRCache.hxx.
Referenced by cacheTTL(), setTTL(), and updateCache().
1.7.5.1