P2PNS name cache module. More...
#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 |
P2PNS name cache module.
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().
{ P2pnsCacheEntry entry; entry.value = value; entry.ttlMessage = ttlMessage; // replace with new value cache.erase(name); cache.insert(make_pair(name, entry)); }
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().
{ P2pnsIdCache::iterator it = idCache.find(key); if (it == idCache.end()) { it = idCache.insert(make_pair(key, P2pnsIdCacheEntry(key))).first; } if (payload != NULL) { it->second.payloadQueue.push_back(*payload); } it->second.lastUsage = simTime(); return &it->second; }
void P2pnsCache::clear | ( | ) | [virtual] |
Clears all stored data items.
Definition at line 67 of file P2pnsCache.cc.
void P2pnsCache::display | ( | ) |
Definition at line 214 of file P2pnsCache.cc.
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.
{ std::map<BinaryValue, P2pnsCacheEntry>::iterator it = cache.find(name); if (it == cache.end()) return BinaryValue::UNSPECIFIED_VALUE; else return it->second.value; }
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().
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().
uint32_t P2pnsCache::getSize | ( | ) | [virtual] |
Returns number of stored data items in the map.
Definition at line 77 of file P2pnsCache.cc.
{ return cache.size(); }
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.
void P2pnsCache::handleMessage | ( | cMessage * | msg | ) | [virtual] |
Definition at line 62 of file P2pnsCache.cc.
{ error("This module doesn't handle messages!"); }
void P2pnsCache::initialize | ( | int | stage | ) | [virtual] |
Definition at line 53 of file P2pnsCache.cc.
{ if (stage != MIN_STAGE_APP) return; WATCH_MAP(cache); WATCH_MAP(idCache); }
bool P2pnsCache::isEmpty | ( | ) | [virtual] |
Checks if the data storage map is empty.
Definition at line 82 of file P2pnsCache.cc.
{ if (cache.size() == 0) return true; else return false; }
virtual int P2pnsCache::numInitStages | ( | void | ) | const [inline, virtual] |
Definition at line 78 of file P2pnsCache.h.
{
return MAX_STAGE_APP;
}
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.
{ cache.erase(name); }
void P2pnsCache::removeIdCacheEntry | ( | const OverlayKey & | key | ) | [virtual] |
Definition at line 119 of file P2pnsCache.cc.
Referenced by P2pns::handleTimerEvent(), P2pns::handleTunnelLookupResponse(), and P2pns::pingTimeout().
{ idCache.erase(key); }
void P2pnsCache::updateDisplayString | ( | ) | [protected] |
Updates the display string.
Definition at line 177 of file P2pnsCache.cc.
void P2pnsCache::updateTooltip | ( | ) | [protected] |
Updates the tooltip.
Definition at line 196 of file P2pnsCache.cc.
{ if (ev.isGUI()) { std::stringstream str; for (uint32_t i = 0; i < cache.size(); i++) { str << getDataAtPos(i); if ( i != cache.size() - 1 ) str << endl; } char buf[1024]; sprintf(buf, "%s", str.str().c_str()); getDisplayString().setTagArg("tt", 0, buf); } }
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().