PastryNeighborhoodSet module. More...
#include <PastryNeighborhoodSet.h>
Public Member Functions | |
void | initializeSet (uint32_t numberOfNeighbors, uint32_t 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 | |
uint32_t | numberOfNeighbors |
std::vector< PastryExtendedNode > | neighbors |
PastryNeighborhoodSet module.
This module contains the NeighborhoodSet of the Pastry implementation.
Definition at line 45 of file PastryNeighborhoodSet.h.
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.
Definition at line 48 of file PastryNeighborhoodSet.cc.
Referenced by Pastry::doSecondStage(), and BasePastry::sendStateTables().
00049 { 00050 uint32_t i = 0; 00051 uint32_t size = 0; 00052 std::vector<PastryExtendedNode>::const_iterator it; 00053 00054 msg->setNeighborhoodSetArraySize(numberOfNeighbors); 00055 for (it = neighbors.begin(); it != neighbors.end(); it++) { 00056 if (!it->node.isUnspecified()) { 00057 ++size; 00058 msg->setNeighborhoodSet(i++, it->node); 00059 } 00060 } 00061 msg->setNeighborhoodSetArraySize(size); 00062 }
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.
Definition at line 128 of file PastryNeighborhoodSet.cc.
Referenced by Pastry::doSecondStage().
void PastryNeighborhoodSet::earlyInit | ( | void | ) | [private, virtual] |
initialize watches etc.
Implements PastryStateObject.
Definition at line 29 of file PastryNeighborhoodSet.cc.
00030 { 00031 WATCH_VECTOR(neighbors); 00032 }
const TransportAddress & PastryNeighborhoodSet::failedNode | ( | const TransportAddress & | failed | ) | [virtual] |
tell the neighborhood set about a failed node
failed | the failed node |
Implements PastryStateObject.
Definition at line 137 of file PastryNeighborhoodSet.cc.
Referenced by Pastry::handleFailedNode(), and Bamboo::handleFailedNode().
00138 { 00139 std::vector<PastryExtendedNode>::iterator it; 00140 00141 for (it = neighbors.begin(); it != neighbors.end(); it++) { 00142 if (it->node.isUnspecified()) break; 00143 if (it->node.getAddress() == failed.getAddress()) { 00144 neighbors.erase(it); 00145 neighbors.push_back(unspecNode()); 00146 break; 00147 } 00148 } 00149 00150 // never ask for repair 00151 return TransportAddress::UNSPECIFIED_NODE; 00152 }
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.
Definition at line 64 of file PastryNeighborhoodSet.cc.
Referenced by BasePastry::findNode().
00066 { 00067 std::vector<PastryExtendedNode>::const_iterator it; 00068 00069 if (optimize) { 00070 // pointer to later return value, initialize to unspecified, so 00071 // the specialCloserCondition() check will be done against our own 00072 // node as long as no node closer to the destination than our own was 00073 // found. 00074 const NodeHandle* ret = &NodeHandle::UNSPECIFIED_NODE; 00075 00076 for (it = neighbors.begin(); it != neighbors.end(); it++) { 00077 if (it->node.isUnspecified()) break; 00078 if (specialCloserCondition(it->node, destination, *ret)) 00079 ret = &(it->node); 00080 } 00081 return *ret; 00082 } else { 00083 for (it = neighbors.begin(); it != neighbors.end(); it++) { 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.
Definition at line 91 of file PastryNeighborhoodSet.cc.
Referenced by BasePastry::findNode().
void PastryNeighborhoodSet::initializeSet | ( | uint32_t | numberOfNeighbors, | |
uint32_t | 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 |
Definition at line 34 of file PastryNeighborhoodSet.cc.
Referenced by BasePastry::baseChangeState().
00037 { 00038 this->owner = owner; 00039 this->numberOfNeighbors = numberOfNeighbors; 00040 this->bitsPerDigit = bitsPerDigit; 00041 if (!neighbors.empty()) neighbors.clear(); 00042 00043 // fill Set with unspecified node handles 00044 for (uint32_t i = numberOfNeighbors; i>0; i--) 00045 neighbors.push_back(unspecNode()); 00046 }
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.
Definition at line 101 of file PastryNeighborhoodSet.cc.
00102 { 00103 std::vector<PastryExtendedNode>::iterator it; 00104 00105 bool nodeAlreadyInVector = false; // was the node already in the list? 00106 bool nodeValueWasChanged = false; // true if the list was changed, false if the rtt was too big 00107 // look for node in the set, if it's there and the value was changed, erase it (since the position is no longer valid) 00108 for (it = neighbors.begin(); it != neighbors.end(); it++) { 00109 if (!it->node.isUnspecified() && it->node == node) { 00110 if (prox == SimTime::getMaxTime() || it->rtt == prox) return false; // nothing to do! 00111 neighbors.erase(it); 00112 nodeAlreadyInVector = true; 00113 break; 00114 } 00115 } 00116 // look for the correct position for the node 00117 for (it = neighbors.begin(); it != neighbors.end(); it++) { 00118 if (it->node.isUnspecified() || (it->rtt > prox)) { 00119 nodeValueWasChanged = true; 00120 break; 00121 } 00122 } 00123 neighbors.insert(it, PastryExtendedNode(node, prox)); // insert the entry there 00124 if (!nodeAlreadyInVector) neighbors.pop_back(); // if a new entry was inserted, erase the last entry 00125 return !nodeAlreadyInVector && nodeValueWasChanged; // return whether a new entry was added 00126 }
std::vector<PastryExtendedNode> PastryNeighborhoodSet::neighbors [private] |
Definition at line 111 of file PastryNeighborhoodSet.h.
Referenced by dumpToStateMessage(), dumpToVector(), earlyInit(), failedNode(), findCloserNode(), findCloserNodes(), initializeSet(), and mergeNode().
uint32_t PastryNeighborhoodSet::numberOfNeighbors [private] |
Definition at line 110 of file PastryNeighborhoodSet.h.
Referenced by dumpToStateMessage().