#include <PastryLeafSet.h>

This module contains the LeafSet of the Pastry implementation.
Definition at line 60 of file PastryLeafSet.h.
Public Member Functions | |
| void | initializeSet (uint32_t numberOfLeaves, uint32_t bitsPerDigit, simtime_t repairTimeout, const NodeHandle &owner, BasePastry *overlay) |
| Initializes the leaf set. | |
| virtual const NodeHandle & | getDestinationNode (const OverlayKey &destination) |
| gets the final node according to the Pastry routing scheme. | |
| 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 leaf set. | |
| void | findCloserNodes (const OverlayKey &destination, NodeVector *nodes) |
| virtual const TransportAddress & | failedNode (const TransportAddress &failed) |
| tells the leafset that a node has failed | |
| virtual const TransportAddress & | repair (const PastryStateMessage *msg, const PastryStateMsgProximity *prox) |
| attempt to repair the leafset using a received REPAIR message | |
| bool | isClosestNode (const OverlayKey &destination) const |
| checks if we are the closest node to key destination in the overlay | |
| virtual void | dumpToStateMessage (PastryStateMessage *msg) const |
| dump content of the set to a PastryStateMessage | |
| virtual void | dumpToStateMessage (PastryLeafsetMessage *msg) const |
| dump content of the set to a PastryLeafsetMessage | |
| virtual const TransportAddress & | getRandomNode () |
| returns a random node from the leafset | |
| bool | mergeNode (const NodeHandle &node, simtime_t prox) |
| merge a node into LeafSet | |
| const NodeHandle & | getPredecessor (void) const |
| return predecessor node for visualizing | |
| const NodeHandle & | getSuccessor (void) const |
| return successor node for visualizing | |
| bool | isValid (void) const |
| check if LeafSet knows at least one node to the left and to the right | |
| virtual void | dumpToVector (std::vector< TransportAddress > &affected) const |
| appends all leaf set entries to a given vector of TransportAddresses, needed to find all Nodes to be notified after joining. | |
| NodeVector * | createSiblingVector (const OverlayKey &key, int numSiblings) const |
| PastryNewLeafsMessage * | getNewLeafsMessage (void) |
| generates a newLeafs-message if LeafSet changed since last call to this method. | |
Private Member Functions | |
| virtual void | earlyInit (void) |
| initialize watches etc. | |
| const NodeHandle & | getBiggestNode (void) const |
| return the node with the biggest key in the LeafSet or NodeHandle::UNSPECIFIED_NODE if LeafSet is empty | |
| const OverlayKey & | getBiggestKey (void) const |
| return the biggest key in the LeafSet or OverlayKey::UNSPECIFIED_KEY if LeafSet is empty | |
| const NodeHandle & | getSmallestNode (void) const |
| return the node with the smallest key in the LeafSet or NodeHandle::UNSPECIFIED_NODE if LeafSet is empty | |
| const OverlayKey & | getSmallestKey (void) const |
| return the smallest key in the LeafSet or OverlayKey::UNSPECIFIED_KEY if LeafSet is empty | |
| bool | isLeft (const OverlayKey &key) const |
| test if a given key should be placed on the left or on the right side of the leaf set | |
| void | insertLeaf (std::vector< NodeHandle >::iterator &it, const NodeHandle &node) |
| insert a leaf at a given position | |
| bool | balanceLeafSet () |
Private Attributes | |
| uint32_t | numberOfLeaves |
| simtime_t | repairTimeout |
| BasePastry * | overlay |
| pointer to the main pastry module | |
| std::vector< NodeHandle > | leaves |
| std::vector< NodeHandle >::iterator | smaller |
| std::vector< NodeHandle >::iterator | bigger |
| std::map< TransportAddress, PLSRepairData > | awaitingRepair |
| bool | newLeafs |
| bool | isFull |
| bool | wasFull |
| void PastryLeafSet::initializeSet | ( | uint32_t | numberOfLeaves, | |
| uint32_t | bitsPerDigit, | |||
| simtime_t | repairTimeout, | |||
| const NodeHandle & | owner, | |||
| BasePastry * | overlay | |||
| ) |
Initializes the leaf set.
This should be called on startup
| numberOfLeaves | Pastry configuration parameter | |
| bitsPerDigit | number of bits per digits | |
| repairTimeout | Pastry configuration parameter | |
| owner | the node this table belongs to | |
| overlay | pointer to the pastry main module |
Definition at line 58 of file PastryLeafSet.cc.
Referenced by BasePastry::baseChangeState().
00063 { 00064 if (numberOfLeaves % 2) throw "numberOfLeaves must be even."; 00065 00066 this->owner = owner; 00067 this->numberOfLeaves = numberOfLeaves; 00068 this->repairTimeout = repairTimeout; 00069 this->bitsPerDigit = bitsPerDigit; 00070 this->overlay = overlay; 00071 00072 if (!leaves.empty()) leaves.clear(); 00073 00074 // fill Set with unspecified node handles 00075 for (uint32_t i = numberOfLeaves; i>0; i--) 00076 leaves.push_back(NodeHandle::UNSPECIFIED_NODE); 00077 00078 // initialize iterators to mark the beginning of bigger/smaller keys 00079 // in the set 00080 bigger = leaves.begin() + (numberOfLeaves >> 1); 00081 smaller = bigger - 1; 00082 00083 // reset repair marker: 00084 if (!awaitingRepair.empty()) awaitingRepair.clear(); 00085 00086 newLeafs = false; 00087 isFull = false; 00088 wasFull = false; 00089 }
| const NodeHandle & PastryLeafSet::getDestinationNode | ( | const OverlayKey & | destination | ) | [virtual] |
gets the final node according to the Pastry routing scheme.
| destination | the destination key |
Reimplemented from PastryStateObject.
Definition at line 106 of file PastryLeafSet.cc.
Referenced by BasePastry::findNode().
00108 { 00109 std::vector<NodeHandle>::const_iterator i; 00110 const OverlayKey* smallest; 00111 const OverlayKey* biggest; 00112 const NodeHandle* ret = &NodeHandle::UNSPECIFIED_NODE; 00113 00114 // check whether destination is inside leafSet: 00115 00116 smallest = &(getSmallestKey()); 00117 biggest = &(getBiggestKey()); 00118 if (smallest->isUnspecified()) smallest = &(owner.key); 00119 if (biggest->isUnspecified()) biggest = &(owner.key); 00120 00121 if (!destination.isBetweenLR(*smallest, *biggest)) return *ret; 00122 00123 // find the closest node: 00124 00125 for (i = leaves.begin(); i != leaves.end(); i++) { 00126 if (i->isUnspecified()) continue; 00127 00128 // note for next line: 00129 // * dereferences iterator, & gets address of element. 00130 if (isCloser(*i, destination, *ret)) ret = &(*i); 00131 } 00132 00133 return *ret; 00134 }
| const NodeHandle & PastryLeafSet::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 leaf 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 452 of file PastryLeafSet.cc.
Referenced by BasePastry::findNode().
00454 { 00455 std::vector<NodeHandle>::const_iterator i; 00456 const NodeHandle* ret = &NodeHandle::UNSPECIFIED_NODE; 00457 00458 // this will only be called after getDestinationNode() returned 00459 // NodeHandle::UNSPECIFIED_NODE, so a closer Node can only be the biggest 00460 // or the smallest node in the LeafSet. 00461 00462 const NodeHandle& smallest = getSmallestNode(); 00463 const NodeHandle& biggest = getBiggestNode(); 00464 00465 if ((!smallest.isUnspecified()) && 00466 (specialCloserCondition(smallest, destination, *ret))) { 00467 if (optimize) ret = &smallest; 00468 else return smallest; 00469 } 00470 00471 if ((!biggest.isUnspecified()) && 00472 (specialCloserCondition(biggest, destination, *ret))) { 00473 if (optimize) ret = &biggest; 00474 else return biggest; 00475 } 00476 00477 return *ret; 00478 }
| void PastryLeafSet::findCloserNodes | ( | const OverlayKey & | destination, | |
| NodeVector * | nodes | |||
| ) | [virtual] |
Implements PastryStateObject.
Definition at line 441 of file PastryLeafSet.cc.
Referenced by BasePastry::findNode().
00443 { 00444 std::vector<NodeHandle>::const_iterator it; 00445 00446 for (it = leaves.begin(); it != leaves.end(); it++) 00447 if (!it->isUnspecified()) 00448 nodes->add(*it); 00449 00450 }
| const TransportAddress & PastryLeafSet::failedNode | ( | const TransportAddress & | failed | ) | [virtual] |
tells the leafset that a node has failed
| failed | the failed node |
Implements PastryStateObject.
Definition at line 480 of file PastryLeafSet.cc.
Referenced by Pastry::handleFailedNode(), and Bamboo::handleFailedNode().
00481 { 00482 std::vector<NodeHandle>::iterator i; 00483 const TransportAddress* ask; 00484 bool left = true; 00485 00486 // search failed node in leafset: 00487 for (i = leaves.begin(); i != leaves.end(); i++) { 00488 if (i == bigger) left = false; 00489 if ((! i->isUnspecified()) && (i->ip == failed.ip)) break; 00490 } 00491 00492 // failed node not in leafset: 00493 if (i == leaves.end()) return TransportAddress::UNSPECIFIED_NODE; 00494 00495 overlay->callUpdate(*i, false); 00496 00497 // remove failed node: 00498 leaves.erase(i); 00499 newLeafs = true; 00500 00501 wasFull = isFull; 00502 isFull = false; 00503 00504 // insert UNSPECIFIED_NODE at front or back and return correct node 00505 // to ask for repair: 00506 if (left) { 00507 leaves.insert(leaves.begin(), NodeHandle::UNSPECIFIED_NODE); 00508 bigger = leaves.begin() + (numberOfLeaves >> 1); 00509 smaller = bigger - 1; 00510 ask = static_cast<const TransportAddress*>(&(getSmallestNode())); 00511 } else { 00512 leaves.push_back(NodeHandle::UNSPECIFIED_NODE); 00513 bigger = leaves.begin() + (numberOfLeaves >> 1); 00514 smaller = bigger - 1; 00515 ask = static_cast<const TransportAddress*>(&(getBiggestNode())); 00516 } 00517 00518 balanceLeafSet(); 00519 LEAF_TEST(); 00520 00521 if (! ask->isUnspecified()) 00522 awaitingRepair[*ask] = PLSRepairData(simTime(), left); 00523 00524 return *ask; 00525 }
| const TransportAddress & PastryLeafSet::repair | ( | const PastryStateMessage * | msg, | |
| const PastryStateMsgProximity * | prox | |||
| ) | [virtual] |
attempt to repair the leafset using a received REPAIR message
| msg | the state message of type REPAIR | |
| prox | record of proximity values matching the state message |
Definition at line 527 of file PastryLeafSet.cc.
Referenced by Pastry::handleStateMessage().
00529 { 00530 std::map<TransportAddress, PLSRepairData>::iterator it; 00531 const TransportAddress* ask; 00532 bool left; 00533 00534 simtime_t now = simTime(); 00535 00536 // first eliminate outdated entries in awaitingRepair: 00537 for (it = awaitingRepair.begin(); it != awaitingRepair.end();) { 00538 if (it->second.ts < (now - repairTimeout)) { 00539 awaitingRepair.erase(it++); 00540 } 00541 else it++; 00542 } 00543 00544 // don't expect any more repair messages: 00545 if (awaitingRepair.empty()) return TransportAddress::UNSPECIFIED_NODE; 00546 00547 // look for source node in our list: 00548 if ( (it = awaitingRepair.find(msg->getSender())) == awaitingRepair.end() ) 00549 return TransportAddress::UNSPECIFIED_NODE; 00550 00551 // which side of the LeafSet is affected: 00552 left = it->second.left; 00553 00554 // remove source node from list: 00555 awaitingRepair.erase(it); 00556 00557 // merge info from repair message: 00558 if (mergeState(msg, prox) || isFull || !wasFull) { 00559 EV << "[PastryLeafSet::repair()]\n" 00560 << " LeafSet repair was successful." 00561 << endl; 00562 return TransportAddress::UNSPECIFIED_NODE; 00563 } else { 00564 // repair did not succeed, try again: 00565 ask = &( left ? getSmallestNode() : getBiggestNode() ); 00566 if (ask->isUnspecified() || *ask == msg->getSender()) { 00567 EV << "[PastryLeafSet::repair()]\n" 00568 << " LeafSet giving up repair attempt." 00569 << endl; 00570 return TransportAddress::UNSPECIFIED_NODE; 00571 } else { 00572 awaitingRepair[*ask] = PLSRepairData(simTime(), left); 00573 } 00574 return *ask; 00575 } 00576 }
| bool PastryLeafSet::isClosestNode | ( | const OverlayKey & | destination | ) | const |
checks if we are the closest node to key destination in the overlay
| destination | the key to check |
Definition at line 136 of file PastryLeafSet.cc.
Referenced by BasePastry::findNode(), and BasePastry::isSiblingFor().
00137 { 00138 // check for simple cases first 00139 if (owner.key == destination) { 00140 return true; 00141 } 00142 00143 if (bigger->isUnspecified() && smaller->isUnspecified()) { 00144 return true; 00145 } 00146 00147 // check if the next bigger or smaller node in the set is closer 00148 // than own node 00149 bool biggerIsCloser = false; 00150 bool smallerIsCloser = false; 00151 00152 if (! bigger->isUnspecified()) { 00153 biggerIsCloser = isCloser(*bigger, destination); 00154 } 00155 if (! smaller->isUnspecified()) { 00156 smallerIsCloser = isCloser(*smaller, destination); 00157 } 00158 00159 // return true if both are not closer 00160 return ((!biggerIsCloser) && (!smallerIsCloser)); 00161 }
| void PastryLeafSet::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 163 of file PastryLeafSet.cc.
Referenced by Bamboo::changeState(), Pastry::doSecondStage(), BasePastry::sendLeafset(), and BasePastry::sendStateTables().
00164 { 00165 uint32_t i = 0; 00166 uint32_t size = 0; 00167 std::vector<NodeHandle>::const_iterator it; 00168 00169 msg->setLeafSetArraySize(numberOfLeaves); 00170 for (it = leaves.begin(); it != leaves.end(); it++) { 00171 if (!it->isUnspecified()) { 00172 ++size; 00173 msg->setLeafSet(i++, *it); 00174 } 00175 } 00176 msg->setLeafSetArraySize(size); 00177 }
| void PastryLeafSet::dumpToStateMessage | ( | PastryLeafsetMessage * | msg | ) | const [virtual] |
dump content of the set to a PastryLeafsetMessage
| msg | the PastryLeafsetMessage to be filled with entries |
Definition at line 180 of file PastryLeafSet.cc.
00181 { 00182 uint32_t i = 0; 00183 uint32_t size = 0; 00184 std::vector<NodeHandle>::const_iterator it; 00185 00186 msg->setLeafSetArraySize(numberOfLeaves); 00187 for (it = leaves.begin(); it != leaves.end(); it++) { 00188 if (!it->isUnspecified()) { 00189 ++size; 00190 msg->setLeafSet(i++, *it); 00191 } 00192 } 00193 msg->setLeafSetArraySize(size); 00194 }
| const TransportAddress & PastryLeafSet::getRandomNode | ( | ) | [virtual] |
returns a random node from the leafset
Definition at line 196 of file PastryLeafSet.cc.
Referenced by Bamboo::doLeafsetMaintenance().
00197 { 00198 //std::vector<NodeHandle>::iterator i; 00199 uint32_t rnd; 00200 int i; 00201 00202 rnd = intuniform(0, numberOfLeaves - 1, 0); 00203 i = rnd; 00204 //while (rnd < leaves.size()) { 00205 while (i < (int)leaves.size()) { 00206 if (!leaves[i].isUnspecified()) return leaves[i]; 00207 else i++;//rnd++; 00208 } 00209 i = rnd; 00210 while (i >= 0) { 00211 if (!leaves[i].isUnspecified()) return leaves[i]; 00212 else i--; 00213 } 00214 EV << "Leafset::getRandomNode() returns UNSPECIFIED_NODE" 00215 "Leafset empty??" << endl; 00216 return TransportAddress::UNSPECIFIED_NODE; 00217 00218 }
| bool PastryLeafSet::mergeNode | ( | const NodeHandle & | node, | |
| simtime_t | prox | |||
| ) | [virtual] |
merge a node into LeafSet
| node | the node to merge | |
| prox | the proximity value of the node |
Implements PastryStateObject.
Definition at line 261 of file PastryLeafSet.cc.
00262 { 00263 std::vector<NodeHandle>::iterator it, it_left, it_right; 00264 const OverlayKey* last_left = &(owner.key); 00265 const OverlayKey* last_right = &(owner.key); 00266 00267 it_left = smaller; 00268 it_right = bigger; 00269 00270 // avoid duplicates 00271 for (it = leaves.begin(); it != leaves.end(); ++it) { 00272 if (it->isUnspecified()) { 00273 isFull = false; 00274 continue; 00275 } 00276 if (it->key == node.key) return false; 00277 } 00278 00279 // look for correct position in left and right half of leafset 00280 while (true) { 00281 if(!isFull) { 00282 // both sides free 00283 if(it_left->key.isUnspecified() && 00284 it_right->key.isUnspecified()) { 00285 insertLeaf(it_left, node); 00286 return true; 00287 } 00288 if (it_left->key.isUnspecified() && 00289 !node.key.isBetween(*last_right, it_right->key)) { 00290 // end of smaller entries found 00291 insertLeaf(it_left, node); 00292 return true; 00293 } 00294 if (it_right->key.isUnspecified() && 00295 !node.key.isBetween(it_left->key, *last_left)) { 00296 // end of bigger entries found 00297 insertLeaf(it_right, node); 00298 return true; 00299 } 00300 } 00301 // left side 00302 if (node.key.isBetween(it_left->key, *last_left)) { 00303 // found correct position for inserting the new entry between 00304 // existing ones 00305 insertLeaf(it_left, node); 00306 return true; 00307 } 00308 // right side 00309 if (node.key.isBetween(*last_right, it_right->key)) { 00310 // found correct position for inserting the new entry between 00311 // existing ones 00312 insertLeaf(it_right, node); 00313 return true; 00314 } 00315 00316 last_right = &(it_right->key); 00317 ++it_right; 00318 00319 if (it_right == leaves.end()) break; 00320 00321 last_left = &(it_left->key); 00322 --it_left; 00323 } 00324 return false; 00325 }
| const NodeHandle & PastryLeafSet::getPredecessor | ( | void | ) | const |
return predecessor node for visualizing
Definition at line 96 of file PastryLeafSet.cc.
Referenced by Pastry::handleTimerEvent(), and BasePastry::updateTooltip().
00097 { 00098 return *smaller; 00099 }
| const NodeHandle & PastryLeafSet::getSuccessor | ( | void | ) | const |
return successor node for visualizing
Definition at line 91 of file PastryLeafSet.cc.
Referenced by Pastry::handleTimerEvent(), and BasePastry::updateTooltip().
00092 { 00093 return *bigger; 00094 }
| bool PastryLeafSet::isValid | ( | void | ) | const |
check if LeafSet knows at least one node to the left and to the right
Definition at line 101 of file PastryLeafSet.cc.
Referenced by createSiblingVector(), Pastry::doSecondStage(), Pastry::handleFailedNode(), and Bamboo::handleFailedNode().
| void PastryLeafSet::dumpToVector | ( | std::vector< TransportAddress > & | affected | ) | const [virtual] |
appends all leaf 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 408 of file PastryLeafSet.cc.
Referenced by Pastry::changeState().
00409 { 00410 std::vector<NodeHandle>::const_iterator it; 00411 00412 for (it = leaves.begin(); it != leaves.end(); it++) 00413 if (!it->isUnspecified()) 00414 affected.push_back(*it); 00415 }
| NodeVector * PastryLeafSet::createSiblingVector | ( | const OverlayKey & | key, | |
| int | numSiblings | |||
| ) | const |
Definition at line 220 of file PastryLeafSet.cc.
Referenced by BasePastry::findNode(), and BasePastry::isSiblingFor().
00222 { 00223 std::vector<NodeHandle>::const_iterator it; 00224 00225 // create temporary comparator 00226 KeyDistanceComparator<KeyRingMetric>* comp = 00227 new KeyDistanceComparator<KeyRingMetric>( key ); 00228 00229 // create result vector 00230 NodeVector* result = new NodeVector( numSiblings, comp ); 00231 00232 result->add(owner); 00233 00234 for (it = leaves.begin(); it != leaves.end(); it++) { 00235 if (!it->isUnspecified()) { 00236 result->add(*it); 00237 } 00238 } 00239 00240 delete comp; 00241 00242 if (!isValid()) { 00243 return result; 00244 } 00245 00246 // if the leafset is not full, we could have a very small network 00247 // => return true (FIXME hack) 00248 if (leaves.front().isUnspecified() || leaves.back().isUnspecified()) { 00249 return result; 00250 } 00251 00252 if ((result->contains(getBiggestKey())) || 00253 (result->contains(getSmallestKey()))) { 00254 delete result; 00255 return NULL; 00256 } 00257 00258 return result; 00259 }
| PastryNewLeafsMessage * PastryLeafSet::getNewLeafsMessage | ( | void | ) |
generates a newLeafs-message if LeafSet changed since last call to this method.
Definition at line 578 of file PastryLeafSet.cc.
Referenced by BasePastry::newLeafs().
00579 { 00580 std::vector<NodeHandle>::const_iterator it; 00581 PastryNewLeafsMessage* msg; 00582 uint32_t i = 0; 00583 00584 if (! newLeafs) return NULL; 00585 newLeafs = false; 00586 00587 msg = new PastryNewLeafsMessage("PastryNewLeafs"); 00588 00589 msg->setLeafsArraySize(numberOfLeaves); 00590 for (it = leaves.begin(); it != leaves.end(); it++) 00591 msg->setLeafs(i++, *it); 00592 00593 msg->setBitLength(PASTRYNEWLEAFS_L(msg)); 00594 return msg; 00595 }
| void PastryLeafSet::earlyInit | ( | void | ) | [private, virtual] |
initialize watches etc.
Implements PastryStateObject.
Definition at line 53 of file PastryLeafSet.cc.
00054 { 00055 WATCH_VECTOR(leaves); 00056 }
| const NodeHandle & PastryLeafSet::getBiggestNode | ( | void | ) | const [private] |
return the node with the biggest key in the LeafSet or NodeHandle::UNSPECIFIED_NODE if LeafSet is empty
Definition at line 429 of file PastryLeafSet.cc.
Referenced by failedNode(), findCloserNode(), getBiggestKey(), and repair().
00430 { 00431 std::vector<NodeHandle>::const_iterator i = leaves.end()-1; 00432 while ((i->isUnspecified()) && (i != bigger)) i--; 00433 return *i; 00434 }
| const OverlayKey & PastryLeafSet::getBiggestKey | ( | void | ) | const [private] |
return the biggest key in the LeafSet or OverlayKey::UNSPECIFIED_KEY if LeafSet is empty
Definition at line 436 of file PastryLeafSet.cc.
Referenced by createSiblingVector(), and getDestinationNode().
00437 { 00438 return getBiggestNode().key; 00439 }
| const NodeHandle & PastryLeafSet::getSmallestNode | ( | void | ) | const [private] |
return the node with the smallest key in the LeafSet or NodeHandle::UNSPECIFIED_NODE if LeafSet is empty
Definition at line 417 of file PastryLeafSet.cc.
Referenced by failedNode(), findCloserNode(), getSmallestKey(), and repair().
00418 { 00419 std::vector<NodeHandle>::const_iterator i = leaves.begin(); 00420 while ((i->isUnspecified()) && (i != smaller)) i++; 00421 return *i; 00422 }
| const OverlayKey & PastryLeafSet::getSmallestKey | ( | void | ) | const [private] |
return the smallest key in the LeafSet or OverlayKey::UNSPECIFIED_KEY if LeafSet is empty
Definition at line 424 of file PastryLeafSet.cc.
Referenced by createSiblingVector(), and getDestinationNode().
00425 { 00426 return getSmallestNode().key; 00427 }
| bool PastryLeafSet::isLeft | ( | const OverlayKey & | key | ) | const [private] |
test if a given key should be placed on the left or on the right side of the leaf set
| key | key to test |
| void PastryLeafSet::insertLeaf | ( | std::vector< NodeHandle >::iterator & | it, | |
| const NodeHandle & | node | |||
| ) | [private] |
insert a leaf at a given position
| it | iterator where to insert the new leaf | |
| node | NodeHandle of new leaf |
Definition at line 327 of file PastryLeafSet.cc.
Referenced by mergeNode().
00329 { 00330 LEAF_TEST(); 00331 bool issmaller = (it <= smaller); 00332 if (issmaller) { 00333 if (!leaves.front().isUnspecified()) { 00334 overlay->callUpdate(leaves.front(), false); 00335 } 00336 overlay->callUpdate(node, true); 00337 00338 leaves.insert(++it, node); 00339 NodeHandle& temp = leaves.front(); 00340 if (!temp.isUnspecified() && leaves.back().isUnspecified()) { 00341 leaves.back() = temp; 00342 } 00343 leaves.erase(leaves.begin()); 00344 00345 00346 } else { 00347 if (!leaves.back().isUnspecified()) { 00348 overlay->callUpdate(leaves.back(), false); 00349 } 00350 overlay->callUpdate(node, true); 00351 00352 leaves.insert(it, node); 00353 NodeHandle& temp = leaves.back(); 00354 if (!temp.isUnspecified() && leaves.front().isUnspecified()) { 00355 leaves.front() = temp; 00356 } 00357 leaves.pop_back(); 00358 } 00359 00360 if (!leaves.front().isUnspecified() && 00361 !leaves.back().isUnspecified()) { 00362 isFull = true; 00363 } else isFull = false; 00364 00365 newLeafs = true; 00366 bigger = leaves.begin() + (numberOfLeaves >> 1); 00367 smaller = bigger - 1; 00368 00369 // ensure balance in leafset 00370 if (!isFull) { 00371 balanceLeafSet(); 00372 } 00373 LEAF_TEST(); 00374 }
| bool PastryLeafSet::balanceLeafSet | ( | ) | [private] |
Definition at line 376 of file PastryLeafSet.cc.
Referenced by failedNode(), and insertLeaf().
00377 { 00378 if (isFull || 00379 (!leaves.front().isUnspecified() && 00380 !(leaves.end() - 2)->isUnspecified()) || 00381 (!leaves.back().isUnspecified() && 00382 !(leaves.begin() + 1)->isUnspecified())) 00383 return false; 00384 00385 std::vector<NodeHandle>::iterator it_left, it_right; 00386 00387 for (it_left = smaller, it_right = bigger; 00388 it_right != leaves.end(); --it_left, ++it_right) { 00389 if (it_left->isUnspecified()) { 00390 if (it_right->isUnspecified() || 00391 (it_right + 1) == leaves.end() || 00392 (it_right + 1)->isUnspecified()) return false; 00393 *it_left = *(it_right + 1); 00394 *(it_right + 1) = NodeHandle::UNSPECIFIED_NODE; 00395 return true; 00396 } else if (it_right->isUnspecified()) { 00397 00398 if (it_left == leaves.begin() || 00399 (it_left - 1)->isUnspecified()) return false; 00400 *it_right = *(it_left - 1); 00401 *(it_left - 1) = NodeHandle::UNSPECIFIED_NODE; 00402 return true; 00403 } 00404 } 00405 return false; // should not happen 00406 }
uint32_t PastryLeafSet::numberOfLeaves [private] |
Definition at line 196 of file PastryLeafSet.h.
Referenced by dumpToStateMessage(), failedNode(), getNewLeafsMessage(), getRandomNode(), and insertLeaf().
simtime_t PastryLeafSet::repairTimeout [private] |
BasePastry* PastryLeafSet::overlay [private] |
pointer to the main pastry module
Definition at line 198 of file PastryLeafSet.h.
Referenced by failedNode(), and insertLeaf().
std::vector<NodeHandle> PastryLeafSet::leaves [private] |
Definition at line 199 of file PastryLeafSet.h.
Referenced by balanceLeafSet(), createSiblingVector(), dumpToStateMessage(), dumpToVector(), earlyInit(), failedNode(), findCloserNodes(), getBiggestNode(), getDestinationNode(), getNewLeafsMessage(), getRandomNode(), getSmallestNode(), initializeSet(), insertLeaf(), and mergeNode().
std::vector<NodeHandle>::iterator PastryLeafSet::smaller [private] |
Definition at line 200 of file PastryLeafSet.h.
Referenced by balanceLeafSet(), failedNode(), getPredecessor(), getSmallestNode(), initializeSet(), insertLeaf(), isClosestNode(), isValid(), and mergeNode().
std::vector<NodeHandle>::iterator PastryLeafSet::bigger [private] |
Definition at line 201 of file PastryLeafSet.h.
Referenced by balanceLeafSet(), failedNode(), getBiggestNode(), getSuccessor(), initializeSet(), insertLeaf(), isClosestNode(), isValid(), and mergeNode().
std::map<TransportAddress, PLSRepairData> PastryLeafSet::awaitingRepair [private] |
Definition at line 203 of file PastryLeafSet.h.
Referenced by failedNode(), initializeSet(), and repair().
bool PastryLeafSet::newLeafs [private] |
Definition at line 205 of file PastryLeafSet.h.
Referenced by failedNode(), getNewLeafsMessage(), initializeSet(), and insertLeaf().
bool PastryLeafSet::isFull [private] |
Definition at line 207 of file PastryLeafSet.h.
Referenced by balanceLeafSet(), failedNode(), initializeSet(), insertLeaf(), mergeNode(), and repair().
bool PastryLeafSet::wasFull [private] |
Definition at line 208 of file PastryLeafSet.h.
Referenced by failedNode(), initializeSet(), and repair().
1.5.5