#include <P2pnsCache.h>
Public Member Functions | |
| virtual int | numInitStages () const |
| virtual void | initialize (int stage) |
| virtual void | handleMessage (cMessage *msg) |
| virtual uint32_t | getSize () |
| Returns number of stored data items in the map. | |
| virtual void | clear () |
| Clears all stored data items. | |
| virtual bool | isEmpty () |
| Checks if the data storage map is empty. | |
| virtual P2pnsIdCacheEntry * | getIdCacheEntry (const OverlayKey &key) |
| virtual P2pnsIdCacheEntry * | addIdCacheEntry (const OverlayKey &key, const BinaryValue *payload=NULL) |
| virtual void | removeIdCacheEntry (const OverlayKey &key) |
| virtual const BinaryValue & | getData (const BinaryValue &name) |
| Returns the value of a stored data item with a given name. | |
| virtual cMessage * | getTtlMessage (const BinaryValue &name) |
| Returns the ttlMessage of a stored data item with a given name. | |
| virtual const BinaryValue & | getDataAtPos (uint32_t pos=0) |
| Returns the value of the data item stored at position pos. | |
| virtual void | addData (BinaryValue name, BinaryValue value, cMessage *ttlMessage=NULL) |
| Store a new data item in the map. | |
| virtual void | removeData (const BinaryValue &name) |
| Removes a certain data item from the map. | |
| void | display () |
Protected Member Functions | |
| void | updateDisplayString () |
| Updates the display string. | |
| void | updateTooltip () |
| Updates the tooltip. | |
Protected Attributes | |
| std::map< BinaryValue, P2pnsCacheEntry > | cache |
| internal representation of the cache | |
| P2pnsIdCache | idCache |
| internal representation of the KBR nodeId cache | |
This modul contains the name cache of the P2PNS implementation.
Definition at line 75 of file P2pnsCache.h.
| void P2pnsCache::addData | ( | BinaryValue | name, | |
| BinaryValue | value, | |||
| cMessage * | ttlMessage = NULL | |||
| ) | [virtual] |
Store a new data item in the map.
| name | The name of the data item to be stored | |
| value | The value of the data item to be stored | |
| ttlMessage | The self-message sent for the ttl expiration |
Definition at line 162 of file P2pnsCache.cc.
Referenced by P2pns::p2pnsRegisterRpc().
00163 { 00164 P2pnsCacheEntry entry; 00165 entry.value = value; 00166 entry.ttlMessage = ttlMessage; 00167 // replace with new value 00168 cache.erase(name); 00169 cache.insert(make_pair(name, entry)); 00170 }
| P2pnsIdCacheEntry * P2pnsCache::addIdCacheEntry | ( | const OverlayKey & | key, | |
| const BinaryValue * | payload = NULL | |||
| ) | [virtual] |
Definition at line 101 of file P2pnsCache.cc.
Referenced by P2pns::tunnel(), and P2pns::updateIdCacheWithNewTransport().
00103 { 00104 P2pnsIdCache::iterator it = idCache.find(key); 00105 00106 if (it == idCache.end()) { 00107 it = idCache.insert(make_pair(key, P2pnsIdCacheEntry(key))).first; 00108 } 00109 00110 if (payload != NULL) { 00111 it->second.payloadQueue.push_back(*payload); 00112 } 00113 00114 it->second.lastUsage = simTime(); 00115 00116 return &it->second; 00117 }
| void P2pnsCache::clear | ( | ) | [virtual] |
Clears all stored data items.
Definition at line 67 of file P2pnsCache.cc.
00068 { 00069 map<BinaryValue, P2pnsCacheEntry>::iterator iter; 00070 for( iter = cache.begin(); iter != cache.end(); iter++ ) { 00071 cancelAndDelete(iter->second.ttlMessage); 00072 } 00073 cache.clear(); 00074 }
| void P2pnsCache::display | ( | ) |
Definition at line 214 of file P2pnsCache.cc.
00215 { 00216 cout << "Content of P2pnsCache:" << endl; 00217 for (std::map<BinaryValue, P2pnsCacheEntry>::iterator it = cache.begin(); 00218 it != cache.end(); it++) { 00219 cout << "name: " << it->first << " Value: " << it->second.value << "End-time: " << it->second.ttlMessage->getArrivalTime() << endl; 00220 } 00221 }
| const BinaryValue & P2pnsCache::getData | ( | const BinaryValue & | name | ) | [virtual] |
Returns the value of a stored data item with a given name.
| name | The name of the data item |
Definition at line 124 of file P2pnsCache.cc.
00124 { 00125 00126 std::map<BinaryValue, P2pnsCacheEntry>::iterator it = cache.find(name); 00127 00128 if (it == cache.end()) 00129 return BinaryValue::UNSPECIFIED_VALUE; 00130 else 00131 return it->second.value; 00132 }
| const BinaryValue & P2pnsCache::getDataAtPos | ( | uint32_t | pos = 0 |
) | [virtual] |
Returns the value of the data item stored at position pos.
| pos | position in data storage map |
Definition at line 146 of file P2pnsCache.cc.
Referenced by updateTooltip().
00147 { 00148 if (pos >= cache.size()) { 00149 error("Index out of bound (P2pnsCache, getDataAtPos())"); 00150 } 00151 00152 std::map<BinaryValue, P2pnsCacheEntry>::iterator it = cache.begin(); 00153 for (uint32_t i= 0; i < pos; i++) { 00154 it++; 00155 if (i == (pos-1)) 00156 return it->second.value; 00157 } 00158 return it->second.value; 00159 }
| P2pnsIdCacheEntry * P2pnsCache::getIdCacheEntry | ( | const OverlayKey & | key | ) | [virtual] |
Definition at line 90 of file P2pnsCache.cc.
Referenced by P2pns::handleTimerEvent(), P2pns::handleTunnelLookupResponse(), P2pns::pingTimeout(), P2pns::tunnel(), and P2pns::updateIdCacheWithNewTransport().
00091 { 00092 P2pnsIdCache::iterator it = idCache.find(key); 00093 00094 if (it != idCache.end()) { 00095 return &it->second; 00096 } else { 00097 return NULL; 00098 } 00099 }
| uint32_t P2pnsCache::getSize | ( | ) | [virtual] |
Returns number of stored data items in the map.
Definition at line 77 of file P2pnsCache.cc.
00078 { 00079 return cache.size(); 00080 }
| cMessage * P2pnsCache::getTtlMessage | ( | const BinaryValue & | name | ) | [virtual] |
Returns the ttlMessage of a stored data item with a given name.
| name | The name of the data item |
Definition at line 136 of file P2pnsCache.cc.
00136 { 00137 std::map<BinaryValue, P2pnsCacheEntry>::iterator it = cache.find(name); 00138 00139 if (it == cache.end()) 00140 return NULL; 00141 else 00142 return it->second.ttlMessage; 00143 }
| void P2pnsCache::handleMessage | ( | cMessage * | msg | ) | [virtual] |
Definition at line 62 of file P2pnsCache.cc.
00063 { 00064 error("This module doesn't handle messages!"); 00065 }
| void P2pnsCache::initialize | ( | int | stage | ) | [virtual] |
Definition at line 53 of file P2pnsCache.cc.
00054 { 00055 if (stage != MIN_STAGE_APP) 00056 return; 00057 00058 WATCH_MAP(cache); 00059 WATCH_MAP(idCache); 00060 }
| bool P2pnsCache::isEmpty | ( | ) | [virtual] |
Checks if the data storage map is empty.
Definition at line 82 of file P2pnsCache.cc.
00083 { 00084 if (cache.size() == 0) 00085 return true; 00086 else 00087 return false; 00088 }
| virtual int P2pnsCache::numInitStages | ( | void | ) | const [inline, virtual] |
| void P2pnsCache::removeData | ( | const BinaryValue & | name | ) | [virtual] |
Removes a certain data item from the map.
| name | The name of the data item to be removed |
Definition at line 172 of file P2pnsCache.cc.
00173 { 00174 cache.erase(name); 00175 }
| void P2pnsCache::removeIdCacheEntry | ( | const OverlayKey & | key | ) | [virtual] |
Definition at line 119 of file P2pnsCache.cc.
Referenced by P2pns::handleTimerEvent(), P2pns::handleTunnelLookupResponse(), and P2pns::pingTimeout().
00120 { 00121 idCache.erase(key); 00122 }
| void P2pnsCache::updateDisplayString | ( | ) | [protected] |
Updates the display string.
Definition at line 177 of file P2pnsCache.cc.
00178 { 00179 // FIXME: doesn't work without tcl/tk 00180 //if (ev.isGUI()) { 00181 if (1) { 00182 char buf[80]; 00183 00184 if (cache.size() == 1) { 00185 sprintf(buf, "1 data item"); 00186 } else { 00187 sprintf(buf, "%zi data items", cache.size()); 00188 } 00189 00190 getDisplayString().setTagArg("t", 0, buf); 00191 getDisplayString().setTagArg("t", 2, "blue"); 00192 } 00193 00194 }
| void P2pnsCache::updateTooltip | ( | ) | [protected] |
Updates the tooltip.
Definition at line 196 of file P2pnsCache.cc.
00197 { 00198 if (ev.isGUI()) { 00199 std::stringstream str; 00200 for (uint32_t i = 0; i < cache.size(); i++) { 00201 str << getDataAtPos(i); 00202 00203 if ( i != cache.size() - 1 ) 00204 str << endl; 00205 } 00206 00207 00208 char buf[1024]; 00209 sprintf(buf, "%s", str.str().c_str()); 00210 getDisplayString().setTagArg("tt", 0, buf); 00211 } 00212 }
std::map<BinaryValue, P2pnsCacheEntry> P2pnsCache::cache [protected] |
internal representation of the cache
Definition at line 155 of file P2pnsCache.h.
Referenced by addData(), clear(), display(), getData(), getDataAtPos(), getSize(), getTtlMessage(), initialize(), isEmpty(), removeData(), updateDisplayString(), and updateTooltip().
P2pnsIdCache P2pnsCache::idCache [protected] |
internal representation of the KBR nodeId cache
Definition at line 156 of file P2pnsCache.h.
Referenced by addIdCacheEntry(), getIdCacheEntry(), initialize(), and removeIdCacheEntry().
1.5.8