OverSim
GiaMessageBookkeeping Class Reference

This class contains all send messages and their timestamp. More...

#include <GiaMessageBookkeeping.h>

Classes

class  GiaNodeQueueCompare
struct  MessageItem

Public Member Functions

 GiaMessageBookkeeping (GiaNeighbors *neighbors, uint32_t timeout)
 Constructor.
 ~GiaMessageBookkeeping ()
 Destructor.
uint32_t getSize ()
void addMessage (GiaIDMessage *msg)
 Add GiaMessage to MessageBookkeeping.
void removeMessage (GiaIDMessage *msg)
 Removes GiaMessage from MessageBookkeeping.
bool contains (GiaIDMessage *msg)
NodeHandle getNextHop (GiaIDMessage *msg)
void removeTimedoutMessages ()
 Removes timedout messages from list.

Protected Attributes

std::map< OverlayKey, MessageItemmessages
 contains all sent messages
GiaNeighborsneighbors
 pointer to our neighbor list
uint32_t timeout

Detailed Description

This class contains all send messages and their timestamp.

It is used for timing out old messages and for biased random walk.

Definition at line 42 of file GiaMessageBookkeeping.h.

Constructor & Destructor Documentation

GiaMessageBookkeeping::GiaMessageBookkeeping ( GiaNeighbors neighbors,
uint32_t  timeout 
)

Constructor.

Parameters
neighborsPointer to neighbors-list
timeoutValue for timing out old messages

Definition at line 30 of file GiaMessageBookkeeping.cc.

{
this->neighbors = neighbors;
this->timeout = timeout;
}
GiaMessageBookkeeping::~GiaMessageBookkeeping ( )

Destructor.

Definition at line 36 of file GiaMessageBookkeeping.cc.

{}

Member Function Documentation

void GiaMessageBookkeeping::addMessage ( GiaIDMessage msg)

Add GiaMessage to MessageBookkeeping.

Parameters
msgThis is a GiaIDMessage

Definition at line 44 of file GiaMessageBookkeeping.cc.

Referenced by Gia::forwardMessage().

{
assert(!(msg->getID().isUnspecified()));
std::vector<GiaNode> remainNodes;
// push all neighbors except the node where message was comming from
// to remainNodes
for ( uint32_t i=0; i<neighbors->getSize(); i++ ) {
if ( neighbors->get(i).getKey() != msg->getSrcNode().getKey())
remainNodes.push_back(neighbors->get(i));
}
MessageItem messageItem;
messageItem.remainNodes = remainNodes;
messageItem.timestamp = simTime();
messages[msg->getID()] = messageItem;
}
bool GiaMessageBookkeeping::contains ( GiaIDMessage msg)
Parameters
msgThis is a GiaIDMessage
Returns
true, if MessageBookkeeping contains GiaMessage

Definition at line 69 of file GiaMessageBookkeeping.cc.

Referenced by Gia::forwardMessage().

{
std::map<OverlayKey, MessageItem>::iterator it = messages.find(msg->getID());
if(it != messages.end())
return true;
return false;
}
NodeHandle GiaMessageBookkeeping::getNextHop ( GiaIDMessage msg)
Parameters
msgThis is a GiaIDMessage
Returns
Next hop to route message to, NULL, if no token available

Definition at line 78 of file GiaMessageBookkeeping.cc.

Referenced by Gia::forwardMessage().

{
if ( neighbors->getSize() > 0 ) {
std::map<OverlayKey, MessageItem>::iterator it = messages.find(msg->getID());
std::priority_queue<FullGiaNodeInfo, std::vector<FullGiaNodeInfo>, GiaNodeQueueCompare> nodeQueue;
if ( it != messages.end() && it->first == msg->getID() ) {
MessageItem messageItem = it->second;
std::vector<GiaNode> remNodes = messageItem.remainNodes;
if ( remNodes.size() == 0) {
for ( uint32_t i=0; i<neighbors->getSize(); i++ ) {
remNodes.push_back(neighbors->get(i));
}
}
for ( uint32_t i=0; i<remNodes.size(); i++ ) {
if(!(remNodes[i].isUnspecified())) {
temp.node = remNodes[i];
temp.info = neighbors->get(temp.node);
if (temp.info) nodeQueue.push(temp);
}
}
if (!nodeQueue.empty()) {
NodeHandle nextHop = nodeQueue.top().node;
GiaNeighborInfo* nextHopInfo = neighbors->get(nextHop);
nodeQueue.pop();
if (nextHopInfo != NULL && nextHopInfo->receivedTokens > 0 ) {
remNodes.clear();
while ( !nodeQueue.empty() ) {
remNodes.push_back(nodeQueue.top().node);
nodeQueue.pop();
}
messageItem.remainNodes = remNodes;
messageItem.timestamp = simTime();
messages[msg->getID()] = messageItem;
return nextHop;
}
}
}
}
}
uint32_t GiaMessageBookkeeping::getSize ( )
Returns
Size of MessageBookkeeping-List

Definition at line 39 of file GiaMessageBookkeeping.cc.

{
return messages.size();
}
void GiaMessageBookkeeping::removeMessage ( GiaIDMessage msg)

Removes GiaMessage from MessageBookkeeping.

Parameters
msgThis is a GiaIDMessage

Definition at line 61 of file GiaMessageBookkeeping.cc.

{
std::map<OverlayKey, MessageItem>::iterator it = messages.find(msg->getID());
// delete message if key is equal
if ( it->first == msg->getID() )
messages.erase(messages.find(msg->getID()));
}
void GiaMessageBookkeeping::removeTimedoutMessages ( )

Removes timedout messages from list.

Definition at line 124 of file GiaMessageBookkeeping.cc.

Referenced by Gia::handleTimerEvent().

{
std::map<OverlayKey, MessageItem>::iterator it = messages.begin();
std::map<OverlayKey, MessageItem>::iterator it2 = messages.begin();
for ( uint32_t i=0; i<messages.size(); i++) {
OverlayKey key = it->first;
MessageItem messageItem = it->second;
it2 = it++;
if (simTime() > (messageItem.timestamp + timeout))
messages.erase(it2);
}
}

Member Data Documentation

std::map<OverlayKey, MessageItem> GiaMessageBookkeeping::messages
protected

contains all sent messages

Definition at line 107 of file GiaMessageBookkeeping.h.

Referenced by addMessage(), contains(), getNextHop(), getSize(), removeMessage(), and removeTimedoutMessages().

GiaNeighbors* GiaMessageBookkeeping::neighbors
protected

pointer to our neighbor list

Definition at line 108 of file GiaMessageBookkeeping.h.

Referenced by addMessage(), getNextHop(), and GiaMessageBookkeeping().

uint32_t GiaMessageBookkeeping::timeout
protected

Definition at line 109 of file GiaMessageBookkeeping.h.

Referenced by GiaMessageBookkeeping(), and removeTimedoutMessages().


The documentation for this class was generated from the following files: