blob: b84f9d02295d9d5a79b3972d832df869e681be89 [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/*
2 * File: ndn_rit.cpp
3 * Author: cawka
4 *
5 * Created on December 15, 2010, 2:02 PM
6 */
7
8#include "ndn_rit.h"
9
10NdnRit::NdnRit( ) { }
11
12NdnRit::~NdnRit( ) { }
13
14
15//find corresponding RIT entry for the given nonce
16RitIterator NdnRit::lookup( int nonce )
17{
18 QNThreadLock lock( &_ritMutex );
19
20 RitIterator entry=_rit.find( nonce );
21 return entry;
22}
23
24
25// add new RIT entry
26// returns false if entry already exists, otherwise returns true
27bool NdnRit::add( int nonce, clocktype expire )
28{
29 QNThreadLock lock( &_ritMutex );
30
31 RitIterator entry=_rit.find( nonce );
32 if( isValid(entry) ) return false;
33
34 RitEntry re;
35 re.nonce = nonce;
36 re.expireTime = expire;
37
38 _rit[ nonce ] = re;
39
40 _ritExpirationList.push_back( &(_rit[nonce]) );
41}
42
43
44void NdnRit::cleanExpired( clocktype time )
45{
46 QNThreadLock lock( &_ritMutex );
47
48 while( !_ritExpirationList.empty() )
49 {
50 RitEntry *head = _ritExpirationList.front( );
51
52 if( head->expireTime <= time )
53 {
54 //delete the head RIT entry
55 _rit.erase( head->nonce );
56 _ritExpirationList.pop_front( );
57 }
58 else
59 break;
60 }
61 //printf("Node %d: RIT entries\n", node->nodeId);
62 //PrintRitEntries(ndn->riList);
63}
64