PastryNeighborhoodSet Class Reference

#include <PastryNeighborhoodSet.h>

Inheritance diagram for PastryNeighborhoodSet:

PastryStateObject List of all members.

Detailed Description

PastryNeighborhoodSet module.

This module contains the NeighborhoodSet of the Pastry implementation.

Author:
Felix Palmen
See also:
Pastry


Public Member Functions

void initializeSet (uint numberOfNeighbors, const NodeHandle &owner)
 Initializes the neighborhood set.
virtual void dumpToStateMessage (PastryStateMessage *msg) const
 dump content of the set to a PastryStateMessage
virtual const NodeHandlefindCloserNode (const OverlayKey &destination, bool optimize=false)
 try to find a node numerically closer to a given key with the same shared prefix as the current node in the neighborhood set.
virtual bool mergeNode (const NodeHandle &node, simtime_t prox)
 merge a node into NeighborhoodSet
virtual void dumpToVector (std::vector< TransportAddress > &affected) const
 appends all neighborhood set entries to a given vector of TransportAddresses, needed to find all Nodes to be notified after joining.
virtual const TransportAddressfailedNode (const TransportAddress &failed)
 tell the neighborhood set about a failed node

Private Member Functions

virtual void earlyInit (void)
 initialize watches etc.

Private Attributes

uint numberOfNeighbors
std::vector< PastryExtendedNodeneighbors


Member Function Documentation

void PastryNeighborhoodSet::initializeSet ( uint  numberOfNeighbors,
const NodeHandle owner 
)

Initializes the neighborhood set.

This should be called on startup

Parameters:
numberOfNeighbors Pastry configuration parameter
owner the node this table belongs to
00036 {
00037     this->owner = owner;
00038     this->numberOfNeighbors = numberOfNeighbors;
00039     
00040     if (!neighbors.empty()) neighbors.clear();
00041 
00042     // fill Set with unspecified node handles
00043     for (uint i = numberOfNeighbors; i>0; i--)
00044         neighbors.push_back(unspecNode);
00045 }

void PastryNeighborhoodSet::dumpToStateMessage ( PastryStateMessage *  msg  )  const [virtual]

dump content of the set to a PastryStateMessage

Parameters:
msg the PastryStateMessage to be filled with entries

Implements PastryStateObject.

00048 {
00049     uint i = 0;
00050     std::vector<PastryExtendedNode>::const_iterator it;
00051 
00052     msg->setNeighborhoodSetArraySize(numberOfNeighbors);
00053     for (it = neighbors.begin(); it != neighbors.end(); it++)
00054         msg->setNeighborhoodSet(i++, it->node);
00055 }

const NodeHandle & PastryNeighborhoodSet::findCloserNode ( const OverlayKey destination,
bool  optimize = false 
) [virtual]

try to find a node numerically closer to a given key with the same shared prefix as the current node in the neighborhood set.

this method is to be called, when a regular next hop couldn't be found or wasn't reachable.

Parameters:
destination the destination key
optimize if set, check all nodes and return the best/closest one
Returns:
a closer NodeHandle or NodeHandle::UNSPECIFIED_NODE if none was found

Implements PastryStateObject.

00059 {
00060     std::vector<PastryExtendedNode>::const_iterator it;
00061 
00062     if (optimize)
00063     {
00064         // pointer to later return value, initialize to unspecified, so
00065         // the specialCloserCondition() check will be done against our own
00066         // node as long as no node closer to the destination than our own was
00067         // found.
00068         const NodeHandle* ret = &NodeHandle::UNSPECIFIED_NODE;
00069 
00070         for (it = neighbors.begin(); it != neighbors.end(); it++)
00071         {
00072             if (it->node.isUnspecified()) break;
00073             if (specialCloserCondition(it->node, destination, *ret))
00074                 ret = &(it->node);
00075         }
00076         return *ret;
00077     }
00078     else
00079     {
00080         for (it = neighbors.begin(); it != neighbors.end(); it++)
00081         {
00082             if (it->node.isUnspecified()) break;
00083             if (specialCloserCondition(it->node, destination)) return it->node;
00084         }
00085         return NodeHandle::UNSPECIFIED_NODE;
00086     }
00087 }

bool PastryNeighborhoodSet::mergeNode ( const NodeHandle node,
simtime_t  prox 
) [virtual]

merge a node into NeighborhoodSet

Parameters:
node the node to merge
prox proximity value of the node
Returns:
true if node was merged

Implements PastryStateObject.

00090 {
00091     std::vector<PastryExtendedNode>::iterator it;
00092 
00093     for (it = neighbors.begin(); it != neighbors.end(); it++)
00094     {
00095         if ((! it->node.isUnspecified()) && (it->node == node)) break;
00096         if ((it->rtt < 0) || (it->rtt > prox))
00097         {
00098             neighbors.insert(it, PastryExtendedNode(node, prox));
00099             neighbors.pop_back();
00100             return true;
00101         }
00102     }
00103     return false;
00104 }

void PastryNeighborhoodSet::dumpToVector ( std::vector< TransportAddress > &  affected  )  const [virtual]

appends all neighborhood set entries to a given vector of TransportAddresses, needed to find all Nodes to be notified after joining.

Parameters:
affected the vector to fill with leaf set entries

Implements PastryStateObject.

00108 {
00109     std::vector<PastryExtendedNode>::const_iterator it;
00110 
00111     for (it = neighbors.begin(); it != neighbors.end(); it++)
00112         if (! it->node.isUnspecified())
00113             affected.push_back(it->node);
00114 }

const TransportAddress & PastryNeighborhoodSet::failedNode ( const TransportAddress failed  )  [virtual]

tell the neighborhood set about a failed node

Parameters:
failed the failed node

Implements PastryStateObject.

00118 {
00119     std::vector<PastryExtendedNode>::iterator it;
00120 
00121     for (it = neighbors.begin(); it != neighbors.end(); it++)
00122     {
00123         if (it->node.isUnspecified()) break;
00124         if (it->node.ip == failed.ip)
00125         {
00126             neighbors.erase(it);
00127             neighbors.push_back(unspecNode);
00128             break;
00129         }
00130     }
00131 
00132     // never ask for repair
00133     return TransportAddress::UNSPECIFIED_NODE;
00134 }

void PastryNeighborhoodSet::earlyInit ( void   )  [private, virtual]

initialize watches etc.

Implements PastryStateObject.

00030 {
00031     WATCH_VECTOR(neighbors);
00032 }


Member Data Documentation

uint PastryNeighborhoodSet::numberOfNeighbors [private]

std::vector<PastryExtendedNode> PastryNeighborhoodSet::neighbors [private]


The documentation for this class was generated from the following files:
Generated on Tue Jul 24 16:51:19 2007 for ITM OverSim by  doxygen 1.5.1