tcpiputils/dnd/inc/cache.h
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // cache.h - the record cache
       
    15 //
       
    16 
       
    17 #ifndef __CACHE_H__
       
    18 #define __CACHE_H__
       
    19 /**
       
    20 @file cache.h
       
    21 DNS cache
       
    22 @internalComponent	Domain Name Resolver
       
    23 */
       
    24 
       
    25 #include "record.h"		// ...for TDndRecordLRU (and indirectly class, type symbols and TInetAddr)
       
    26 
       
    27 const TInt KDndMaxRecords = 100;	//< Maximum mumber of records allowed in the cache.
       
    28 
       
    29 class CDndNameSpace;
       
    30 class CDndEngine;
       
    31 
       
    32 /**
       
    33 // The cache maintains a collection of (question, answer) pairs.
       
    34 //
       
    35 // The question (= the search key for the cache) has the
       
    36 // following components:
       
    37 //
       
    38 // @li namespace id
       
    39 // @li domain-name (dotted notation)
       
    40 // @li DNS query type (EDnsQType)
       
    41 // @li DNS query class (EDnsQClass)
       
    42 //
       
    43 // The answer is contained within CDndRecord class. Among other
       
    44 // things, it contains the full original reply from some DNS server
       
    45 // for the question.
       
    46 //
       
    47 // The cache is implemented as a forest of trees, one tree
       
    48 // for each name space. Each component of the domain-name
       
    49 // becomes a node in the tree. A node at any non-leaf level can have
       
    50 // zero or more answers attached (for. example, the domain name "nokia.fi"
       
    51 // can have both "A" (address) and "NS" (name server) answers
       
    52 // associated it.
       
    53 //
       
    54 // The leaf nodes must have at least one answer. When
       
    55 // the last answer is expired or otherwise removed from a leaf node,
       
    56 // the node itself is also removed. A tree containing no answers
       
    57 // consists just of the root node (name space node).
       
    58 //
       
    59 // For example, if in the below example, the "A" answer associated with
       
    60 // query (namespace=\\<global\\>, domain-name="www.nokia.com", query=A, class=IN)
       
    61 // is removed, then also the nodes for "www" and "nokia" are pruned away.
       
    62 @verbatim
       
    63 
       
    64                       cache
       
    65                   .............
       
    66               <global>          <local>
       
    67                 / |              /  \
       
    68               fi com            |    |
       
    69              /    |  \         muu  foo
       
    70             /     |    \        |  /   \ 
       
    71         nokia  symbian nokia  ..A.A....AAAA... (lru)
       
    72        / |  \     |      |   .
       
    73     ..A..NS www  www    www .
       
    74            . |    |      | .
       
    75             .A....A......A
       
    76 @endverbatim
       
    77 // The tree implementation is not directly visible outside the cache
       
    78 // implementation. The CDndCache::FindL returns only a pointer to the
       
    79 // answer (CDndRecord).
       
    80 //
       
    81 // There is a limit to the number of answers (KDndMaxRecords) that
       
    82 // can be stored. If this limit is reached, the <b>least recently used</b>
       
    83 // answers are deleted, if possible. An answer cannot be deleted
       
    84 // is it is currently being used (locked) by some resolver.
       
    85 */
       
    86 class CDndCache : public CBase
       
    87 	{
       
    88 	// See implementation for methods comments!
       
    89 public:
       
    90 	CDndCache();
       
    91 	void ConstructL();
       
    92 	~CDndCache();
       
    93 
       
    94 	TInt GetServerAddress(const TUint32 aNameSpace, TInetAddr &aAddr);
       
    95 	void SetServerAddress(const TUint32 aNameSpace, const TInetAddr &aAddr, const TInt aState);
       
    96 	CDndRecord *FindL(const TUint32 aNameSpace, const TDesC8 &aName, const EDnsQType aType, const EDnsQClass aClass, 
       
    97 						const TTime &aReqTime);		
       
    98 	void Dump(CDndEngine &aControl);
       
    99 	void Flush();
       
   100 private:
       
   101 	CDndNameSpace *GetNameSpace(const TUint32 aNameSpace);
       
   102 	// The roots of the name-spaces
       
   103 	CDndNameSpace *iRootList;
       
   104 	// The LRU list of cache records
       
   105 	TDndRecordLRU iRecordList;
       
   106 	};
       
   107 
       
   108 #endif