reSIProcate/rutil  9694
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
resip::RRCache Class Reference

#include <RRCache.hxx>

Collaboration diagram for resip::RRCache:
Collaboration graph
[legend]

List of all members.

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< DataDataArr

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
LruListTypemLruHead
Result Empty
RRSet mRRSet
RRFactory< DnsHostRecordmHostRecordFactory
RRFactory< DnsSrvRecordmSrvRecordFactory
RRFactory< DnsAAAARecordmAAAARecordFactory
RRFactory< DnsNaptrRecordmNaptrRecordFacotry
RRFactory< DnsCnameRecordmCnameRecordFactory
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

Detailed Description

Definition at line 21 of file RRCache.hxx.


Member Typedef Documentation

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.


Constructor & Destructor Documentation

RRCache::RRCache ( )
RRCache::~RRCache ( )

Definition at line 64 of file RRCache.cxx.

References cleanup().

{
   cleanup();
}

Here is the call graph for this function:


Member Function Documentation

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();
}

Here is the call graph for this function:

void RRCache::cleanup ( ) [private]

Definition at line 197 of file RRCache.cxx.

References mRRSet.

Referenced by clearCache(), and ~RRCache().

{
   for (std::set<RRList*, CompareT>::iterator it = mRRSet.begin(); it != mRRSet.end(); it++)
   {
      (*it)->remove();
      delete *it;
   }
   mRRSet.clear();
}
void RRCache::clearCache ( )

Definition at line 184 of file RRCache.cxx.

References cleanup().

Referenced by resip::DnsStub::doClearDnsCache().

{
    cleanup();
}

Here is the call graph for this function:

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);         
}

Here is the call graph for this function:

void RRCache::logCache ( )

Definition at line 239 of file RRCache.cxx.

References mRRSet.

Referenced by resip::DnsStub::doLogDnsCache().

{
   for (std::set<RRList*, CompareT>::iterator it = mRRSet.begin(); it != mRRSet.end(); it++)
   {
      (*it)->log();
   }
}
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;
      }
   }
}

Here is the call graph for this function:

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);
}

Here is the call graph for this function:

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().

{
   node->remove();
   mLruHead->push_back(node);
}

Here is the call graph for this function:

void RRCache::updateCache ( const Data target,
const int  rrType,
Itr  begin,
Itr  end 
)

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;
}

Here is the call graph for this function:

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;
}

Here is the call graph for this function:


Member Data Documentation

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.

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().

Definition at line 94 of file RRCache.hxx.

Referenced by RRCache(), and updateCache().

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().

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().

unsigned int resip::RRCache::mSize [private]

Definition at line 97 of file RRCache.hxx.

Referenced by purge(), and setSize().

Definition at line 88 of file RRCache.hxx.

Referenced by RRCache().

Definition at line 96 of file RRCache.hxx.

Referenced by cacheTTL(), setTTL(), and updateCache().


The documentation for this class was generated from the following files: