#include <PastryNeighborhoodSet.h>
This module contains the NeighborhoodSet of the Pastry implementation.
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 NodeHandle & | findCloserNode (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. | |
void | findCloserNodes (const OverlayKey &destination, NodeVector *nodes) |
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 TransportAddress & | failedNode (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 < PastryExtendedNode > | neighbors |
void PastryNeighborhoodSet::initializeSet | ( | uint | numberOfNeighbors, | |
const NodeHandle & | owner | |||
) |
Initializes the neighborhood set.
This should be called on startup
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
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.
destination | the destination key | |
optimize | if set, check all nodes and return the best/closest one |
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 }
void PastryNeighborhoodSet::findCloserNodes | ( | const OverlayKey & | destination, | |
NodeVector * | nodes | |||
) | [virtual] |
Implements PastryStateObject.
00091 { 00092 std::vector<PastryExtendedNode>::const_iterator it; 00093 00094 for (it = neighbors.begin(); it != neighbors.end(); it++) 00095 if (! it->node.isUnspecified()) 00096 nodes->add(it->node); 00097 }
bool PastryNeighborhoodSet::mergeNode | ( | const NodeHandle & | node, | |
simtime_t | prox | |||
) | [virtual] |
merge a node into NeighborhoodSet
node | the node to merge | |
prox | proximity value of the node |
Implements PastryStateObject.
00100 { 00101 std::vector<PastryExtendedNode>::iterator it; 00102 00103 for (it = neighbors.begin(); it != neighbors.end(); it++) 00104 { 00105 if ((! it->node.isUnspecified()) && (it->node == node)) break; 00106 if ((it->rtt < 0) || (it->rtt > prox)) 00107 { 00108 neighbors.insert(it, PastryExtendedNode(node, prox)); 00109 neighbors.pop_back(); 00110 return true; 00111 } 00112 } 00113 return false; 00114 }
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.
affected | the vector to fill with leaf set entries |
Implements PastryStateObject.
00118 { 00119 std::vector<PastryExtendedNode>::const_iterator it; 00120 00121 for (it = neighbors.begin(); it != neighbors.end(); it++) 00122 if (! it->node.isUnspecified()) 00123 affected.push_back(it->node); 00124 }
const TransportAddress & PastryNeighborhoodSet::failedNode | ( | const TransportAddress & | failed | ) | [virtual] |
tell the neighborhood set about a failed node
failed | the failed node |
Implements PastryStateObject.
00128 { 00129 std::vector<PastryExtendedNode>::iterator it; 00130 00131 for (it = neighbors.begin(); it != neighbors.end(); it++) 00132 { 00133 if (it->node.isUnspecified()) break; 00134 if (it->node.ip == failed.ip) 00135 { 00136 neighbors.erase(it); 00137 neighbors.push_back(unspecNode); 00138 break; 00139 } 00140 } 00141 00142 // never ask for repair 00143 return TransportAddress::UNSPECIFIED_NODE; 00144 }
void PastryNeighborhoodSet::earlyInit | ( | void | ) | [private, virtual] |
initialize watches etc.
Implements PastryStateObject.
00030 { 00031 WATCH_VECTOR(neighbors); 00032 }
uint PastryNeighborhoodSet::numberOfNeighbors [private] |
std::vector<PastryExtendedNode> PastryNeighborhoodSet::neighbors [private] |