#include <PastryNeighborhoodSet.h>
This module contains the NeighborhoodSet of the Pastry implementation.
Public Member Functions | |
void | initializeSet (uint numberOfNeighbors, uint bitsPerDigit, 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, | |
uint | bitsPerDigit, | |||
const NodeHandle & | owner | |||
) |
Initializes the neighborhood set.
This should be called on startup
numberOfNeighbors | Pastry configuration parameter | |
bitsPerDigit | number of bits per digits | |
owner | the node this table belongs to |
Referenced by BasePastry::baseChangeState().
00037 { 00038 this->owner = owner; 00039 this->numberOfNeighbors = numberOfNeighbors; 00040 this->bitsPerDigit = bitsPerDigit; 00041 00042 if (!neighbors.empty()) neighbors.clear(); 00043 00044 // fill Set with unspecified node handles 00045 for (uint i = numberOfNeighbors; i>0; i--) 00046 neighbors.push_back(unspecNode); 00047 }
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.
Referenced by BasePastry::sendStateTables().
00050 { 00051 uint i = 0; 00052 std::vector<PastryExtendedNode>::const_iterator it; 00053 00054 msg->setNeighborhoodSetArraySize(numberOfNeighbors); 00055 for (it = neighbors.begin(); it != neighbors.end(); it++) 00056 msg->setNeighborhoodSet(i++, it->node); 00057 }
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.
Referenced by BasePastry::findNode().
00061 { 00062 std::vector<PastryExtendedNode>::const_iterator it; 00063 00064 if (optimize) 00065 { 00066 // pointer to later return value, initialize to unspecified, so 00067 // the specialCloserCondition() check will be done against our own 00068 // node as long as no node closer to the destination than our own was 00069 // found. 00070 const NodeHandle* ret = &NodeHandle::UNSPECIFIED_NODE; 00071 00072 for (it = neighbors.begin(); it != neighbors.end(); it++) 00073 { 00074 if (it->node.isUnspecified()) break; 00075 if (specialCloserCondition(it->node, destination, *ret)) 00076 ret = &(it->node); 00077 } 00078 return *ret; 00079 } 00080 else 00081 { 00082 for (it = neighbors.begin(); it != neighbors.end(); it++) 00083 { 00084 if (it->node.isUnspecified()) break; 00085 if (specialCloserCondition(it->node, destination)) return it->node; 00086 } 00087 return NodeHandle::UNSPECIFIED_NODE; 00088 } 00089 }
void PastryNeighborhoodSet::findCloserNodes | ( | const OverlayKey & | destination, | |
NodeVector * | nodes | |||
) | [virtual] |
Implements PastryStateObject.
Referenced by BasePastry::findNode().
00093 { 00094 std::vector<PastryExtendedNode>::const_iterator it; 00095 00096 for (it = neighbors.begin(); it != neighbors.end(); it++) 00097 if (! it->node.isUnspecified()) 00098 nodes->add(it->node); 00099 }
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.
00102 { 00103 std::vector<PastryExtendedNode>::iterator it; 00104 00105 for (it = neighbors.begin(); it != neighbors.end(); it++) 00106 { 00107 if ((! it->node.isUnspecified()) && (it->node == node)) break; 00108 if ((it->rtt < 0) || (it->rtt > prox)) 00109 { 00110 neighbors.insert(it, PastryExtendedNode(node, prox)); 00111 neighbors.pop_back(); 00112 return true; 00113 } 00114 } 00115 return false; 00116 }
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.
Referenced by Pastry::doSecondStage().
00120 { 00121 std::vector<PastryExtendedNode>::const_iterator it; 00122 00123 for (it = neighbors.begin(); it != neighbors.end(); it++) 00124 if (! it->node.isUnspecified()) 00125 affected.push_back(it->node); 00126 }
const TransportAddress & PastryNeighborhoodSet::failedNode | ( | const TransportAddress & | failed | ) | [virtual] |
tell the neighborhood set about a failed node
failed | the failed node |
Implements PastryStateObject.
Referenced by Pastry::handleFailedNode(), and Bamboo::handleFailedNode().
00130 { 00131 std::vector<PastryExtendedNode>::iterator it; 00132 00133 for (it = neighbors.begin(); it != neighbors.end(); it++) 00134 { 00135 if (it->node.isUnspecified()) break; 00136 if (it->node.ip == failed.ip) 00137 { 00138 neighbors.erase(it); 00139 neighbors.push_back(unspecNode); 00140 break; 00141 } 00142 } 00143 00144 // never ask for repair 00145 return TransportAddress::UNSPECIFIED_NODE; 00146 }
void PastryNeighborhoodSet::earlyInit | ( | void | ) | [private, virtual] |
initialize watches etc.
Implements PastryStateObject.
00030 { 00031 WATCH_VECTOR(neighbors); 00032 }
uint PastryNeighborhoodSet::numberOfNeighbors [private] |
Referenced by dumpToStateMessage().
std::vector<PastryExtendedNode> PastryNeighborhoodSet::neighbors [private] |
Referenced by dumpToStateMessage(), dumpToVector(), earlyInit(), failedNode(), findCloserNode(), findCloserNodes(), initializeSet(), and mergeNode().