#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 |
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 49 of file PastryNeighborhoodSet.cc.
Referenced by Pastry::doSecondStage(), and BasePastry::sendStateTables().
00050 { 00051 uint32_t i = 0; 00052 uint32_t size = 0; 00053 std::vector<PastryExtendedNode>::const_iterator it; 00054 00055 msg->setNeighborhoodSetArraySize(numberOfNeighbors); 00056 for (it = neighbors.begin(); it != neighbors.end(); it++) { 00057 if (!it->node.isUnspecified()) { 00058 ++size; 00059 msg->setNeighborhoodSet(i++, it->node); 00060 } 00061 } 00062 msg->setNeighborhoodSetArraySize(size); 00063 }
| 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 129 of file PastryNeighborhoodSet.cc.
Referenced by Pastry::doSecondStage().
00130 { 00131 std::vector<PastryExtendedNode>::const_iterator it; 00132 00133 for (it = neighbors.begin(); it != neighbors.end(); it++) 00134 if (! it->node.isUnspecified()) 00135 affected.push_back(it->node); 00136 }
| 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 138 of file PastryNeighborhoodSet.cc.
Referenced by Pastry::handleFailedNode(), and Bamboo::handleFailedNode().
00139 { 00140 std::vector<PastryExtendedNode>::iterator it; 00141 00142 for (it = neighbors.begin(); it != neighbors.end(); it++) { 00143 if (it->node.isUnspecified()) break; 00144 if (it->node.getAddress() == failed.getAddress()) { 00145 neighbors.erase(it); 00146 neighbors.push_back(unspecNode()); 00147 break; 00148 } 00149 } 00150 00151 // never ask for repair 00152 return TransportAddress::UNSPECIFIED_NODE; 00153 }
| 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 65 of file PastryNeighborhoodSet.cc.
Referenced by BasePastry::findNode().
00067 { 00068 std::vector<PastryExtendedNode>::const_iterator it; 00069 00070 if (optimize) { 00071 // pointer to later return value, initialize to unspecified, so 00072 // the specialCloserCondition() check will be done against our own 00073 // node as long as no node closer to the destination than our own was 00074 // found. 00075 const NodeHandle* ret = &NodeHandle::UNSPECIFIED_NODE; 00076 00077 for (it = neighbors.begin(); it != neighbors.end(); it++) { 00078 if (it->node.isUnspecified()) break; 00079 if (specialCloserCondition(it->node, destination, *ret)) 00080 ret = &(it->node); 00081 } 00082 return *ret; 00083 } else { 00084 for (it = neighbors.begin(); it != neighbors.end(); it++) { 00085 if (it->node.isUnspecified()) break; 00086 if (specialCloserCondition(it->node, destination)) return it->node; 00087 } 00088 return NodeHandle::UNSPECIFIED_NODE; 00089 } 00090 }
| void PastryNeighborhoodSet::findCloserNodes | ( | const OverlayKey & | destination, | |
| NodeVector * | nodes | |||
| ) | [virtual] |
Implements PastryStateObject.
Definition at line 92 of file PastryNeighborhoodSet.cc.
Referenced by BasePastry::findNode().
00094 { 00095 std::vector<PastryExtendedNode>::const_iterator it; 00096 00097 for (it = neighbors.begin(); it != neighbors.end(); it++) 00098 if (! it->node.isUnspecified()) 00099 nodes->add(it->node); 00100 }
| 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 00042 if (!neighbors.empty()) neighbors.clear(); 00043 00044 // fill Set with unspecified node handles 00045 for (uint32_t i = numberOfNeighbors; i>0; i--) 00046 neighbors.push_back(unspecNode()); 00047 }
| 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 102 of file PastryNeighborhoodSet.cc.
00103 { 00104 std::vector<PastryExtendedNode>::iterator it; 00105 00106 bool nodeAlreadyInVector = false; // was the node already in the list? 00107 bool nodeValueWasChanged = false; // true if the list was changed, false if the rtt was too big 00108 // look for node in the set, if it's there and the value was changed, erase it (since the position is no longer valid) 00109 for (it = neighbors.begin(); it != neighbors.end(); it++) { 00110 if (!it->node.isUnspecified() && it->node == node) { 00111 if (prox == SimTime::getMaxTime() || it->rtt == prox) return false; // nothing to do! 00112 neighbors.erase(it); 00113 nodeAlreadyInVector = true; 00114 break; 00115 } 00116 } 00117 // look for the correct position for the node 00118 for (it = neighbors.begin(); it != neighbors.end(); it++) { 00119 if (it->node.isUnspecified() || it->rtt > prox) { 00120 nodeValueWasChanged = true; 00121 break; 00122 } 00123 } 00124 neighbors.insert(it, PastryExtendedNode(node, prox)); // insert the entry there 00125 if (!nodeAlreadyInVector) neighbors.pop_back(); // if a new entry was inserted, erase the last entry 00126 return !nodeAlreadyInVector && nodeValueWasChanged; // return whether a new entry was added 00127 }
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] |
1.5.8