P2PNS name cache module.
More...
#include <P2pnsCache.h>
Detailed Description
P2PNS name cache module.
This modul contains the name cache of the P2PNS implementation.
- Author
- Ingmar Baumgart
- See Also
- P2pns.cc
Definition at line 75 of file P2pnsCache.h.
Member Function Documentation
Store a new data item in the map.
- Parameters
-
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.
{
cache.insert(make_pair(name, entry));
}
Definition at line 101 of file P2pnsCache.cc.
{
P2pnsIdCache::iterator it =
idCache.find(key);
}
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.
{
map<BinaryValue, P2pnsCacheEntry>::iterator iter;
for( iter =
cache.begin(); iter !=
cache.end(); iter++ ) {
cancelAndDelete(iter->second.ttlMessage);
}
}
void P2pnsCache::display |
( |
| ) |
|
Definition at line 214 of file P2pnsCache.cc.
{
cout << "Content of P2pnsCache:" << endl;
for (std::map<BinaryValue, P2pnsCacheEntry>::iterator it =
cache.begin();
it !=
cache.end(); it++) {
cout << "name: " << it->first << " Value: " << it->second.value << "End-time: " << it->second.ttlMessage->getArrivalTime() << endl;
}
}
Returns the value of a stored data item with a given name.
- Parameters
-
name | The name of the data item |
- Returns
- The value of the data item with the given name
Definition at line 124 of file P2pnsCache.cc.
{
std::map<BinaryValue, P2pnsCacheEntry>::iterator it =
cache.find(name);
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.
- Parameters
-
pos | position in data storage map |
- Returns
- The value of the data item at position pos
Definition at line 146 of file P2pnsCache.cc.
{
if (pos >=
cache.size()) {
error(
"Index out of bound (P2pnsCache, getDataAtPos())");
}
std::map<BinaryValue, P2pnsCacheEntry>::iterator it =
cache.begin();
for (uint32_t i= 0; i < pos; i++) {
it++;
if (i == (pos-1))
return it->second.value;
}
return it->second.value;
}
Definition at line 90 of file P2pnsCache.cc.
{
P2pnsIdCache::iterator it =
idCache.find(key);
return &it->second;
} else {
return NULL;
}
}
uint32_t P2pnsCache::getSize |
( |
| ) |
|
|
virtual |
Returns number of stored data items in the map.
- Returns
- number of stored data items
Definition at line 77 of file P2pnsCache.cc.
cMessage * P2pnsCache::getTtlMessage |
( |
const BinaryValue & |
name | ) |
|
|
virtual |
Returns the ttlMessage of a stored data item with a given name.
- Parameters
-
name | The name of the data item |
- Returns
- The ttlMessage of the data item with the given name
Definition at line 136 of file P2pnsCache.cc.
{
std::map<BinaryValue, P2pnsCacheEntry>::iterator it =
cache.find(name);
return NULL;
else
return it->second.ttlMessage;
}
void P2pnsCache::handleMessage |
( |
cMessage * |
msg | ) |
|
|
virtual |
void P2pnsCache::initialize |
( |
int |
stage | ) |
|
|
virtual |
bool P2pnsCache::isEmpty |
( |
| ) |
|
|
virtual |
Checks if the data storage map is empty.
- Returns
- returns false if there are stored data items, true otherwise.
Definition at line 82 of file P2pnsCache.cc.
{
return true;
else
return false;
}
virtual int P2pnsCache::numInitStages |
( |
void |
| ) |
const |
|
inlinevirtual |
void P2pnsCache::removeData |
( |
const BinaryValue & |
name | ) |
|
|
virtual |
Removes a certain data item from the map.
- Parameters
-
name | The name of the data item to be removed |
Definition at line 172 of file P2pnsCache.cc.
void P2pnsCache::removeIdCacheEntry |
( |
const OverlayKey & |
key | ) |
|
|
virtual |
void P2pnsCache::updateDisplayString |
( |
| ) |
|
|
protected |
Updates the display string.
Definition at line 177 of file P2pnsCache.cc.
{
if (1) {
char buf[80];
sprintf(buf, "1 data item");
} else {
sprintf(buf,
"%zi data items",
cache.size());
}
getDisplayString().setTagArg("t", 0, buf);
getDisplayString().setTagArg("t", 2, "blue");
}
}
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++) {
if ( i !=
cache.size() - 1 )
str << endl;
}
char buf[1024];
sprintf(buf, "%s", str.str().c_str());
getDisplayString().setTagArg("tt", 0, buf);
}
}
Member Data Documentation
internal representation of the cache
Definition at line 155 of file P2pnsCache.h.
internal representation of the KBR nodeId cache
Definition at line 156 of file P2pnsCache.h.
The documentation for this class was generated from the following files: