32 uint32_t i = 0, j = leaves.size() - 1;\
33 while (leaves[i].isUnspecified() && i < j) ++i;\
34 while (leaves[j].isUnspecified() && i < j) --j;\
36 if (!owner.getKey().isBetween(leaves[(leaves.size() / 2) - 1].getKey(),\
37 leaves[leaves.size() / 2].getKey()))\
38 ASSERT2(false, "leafset broken!");\
39 for (uint32_t ci = i + 1; ci < j; ++ci) {\
40 if (leaves[ci - 1].getKey() >= leaves[ci].getKey()) {\
44 if (leaves[j].getKey() >= leaves[i].getKey()) count++;\
45 ASSERT2(count <= 1, "leafset broken!");\
48 #define LEAF_TEST() {}
62 uint32_t bitsPerDigit,
63 simtime_t repairTimeout,
67 if (numberOfLeaves % 2)
throw "numberOfLeaves must be even.";
78 for (uint32_t i = numberOfLeaves; i>0; i--)
109 return (!(
smaller->isUnspecified() ||
bigger->isUnspecified()));
115 std::vector<NodeHandle>::const_iterator i;
127 if (!destination.
isBetweenLR(*smallest, *biggest))
return *ret;
132 if (i->isUnspecified())
continue;
136 if (
isCloser(*i, destination, *ret)) ret = &(*i);
156 bool biggerIsCloser =
false;
157 bool smallerIsCloser =
false;
159 if (!
bigger->isUnspecified()) {
162 if (!
smaller->isUnspecified()) {
167 return ((!biggerIsCloser) && (!smallerIsCloser));
175 std::vector<NodeHandle>::const_iterator it;
179 if (!it->isUnspecified()) {
196 while (i < (
int)
leaves.size()) {
205 EV <<
"Leafset::getRandomNode() returns UNSPECIFIED_NODE"
206 "Leafset empty??" << endl;
213 int numSiblings)
const
215 std::vector<NodeHandle>::const_iterator it;
227 if (!it->isUnspecified()) {
240 if (
leaves.front().isUnspecified() ||
leaves.back().isUnspecified()) {
258 std::vector<NodeHandle>::iterator it, it_left, it_right;
267 if (it->isUnspecified()) {
271 if (it->getKey() == node.
getKey())
return false;
278 if(it_left->getKey().isUnspecified() &&
279 it_right->getKey().isUnspecified()) {
283 if (it_left->getKey().isUnspecified() &&
289 if (it_right->getKey().isUnspecified() &&
311 last_right = &(it_right->getKey());
314 if (it_right ==
leaves.end())
break;
316 last_left = &(it_left->getKey());
329 bool issmaller = (it <=
smaller);
331 leaves.insert(++it, node);
333 if (!
leaves.front().isUnspecified()) {
334 assert(
leaves.front() != node);
336 if (
leaves.back().isUnspecified()) {
340 <<
" " <<
leaves.front().getIp() <<
" switched sides"
345 <<
" " <<
leaves.front().getIp() <<
" replaced with " << node.
getIp()
351 <<
" " << node.
getIp() <<
" added"
361 if (!
leaves.back().isUnspecified()) {
362 assert(
leaves.back() != node);
364 if (
leaves.front().isUnspecified()) {
369 <<
" " <<
leaves.back().getIp() <<
" switched sides"
375 <<
" " <<
leaves.back().getIp() <<
" replaced with " << node.
getIp()
381 <<
" " << node.
getIp() <<
" added"
388 if (!
leaves.front().isUnspecified() &&
389 !
leaves.back().isUnspecified()) {
410 (!
leaves.front().isUnspecified() &&
411 !(
leaves.end() - 2)->isUnspecified()) ||
412 (!
leaves.back().isUnspecified() &&
413 !(
leaves.begin() + 1)->isUnspecified()))
416 std::vector<NodeHandle>::iterator it_left, it_right;
419 it_right !=
leaves.end(); --it_left, ++it_right) {
420 if (it_left->isUnspecified()) {
421 if (it_right->isUnspecified() ||
422 (it_right + 1) ==
leaves.end() ||
423 (it_right + 1)->isUnspecified())
return false;
424 *it_left = *(it_right + 1);
427 }
else if (it_right->isUnspecified()) {
429 if (it_left ==
leaves.begin() ||
430 (it_left - 1)->isUnspecified())
return false;
431 *it_right = *(it_left - 1);
436 throw cRuntimeError(
"This should not happen!");
443 std::vector<NodeHandle>::const_iterator it;
446 if (!it->isUnspecified())
447 affected.push_back(*it);
453 std::vector<NodeHandle>::const_iterator i =
leaves.begin();
454 while ((i->isUnspecified()) && (i !=
smaller)) i++;
468 std::vector<NodeHandle>::const_iterator i =
leaves.end()-1;
469 while ((i->isUnspecified()) && (i !=
bigger)) i--;
484 std::vector<NodeHandle>::const_iterator it;
487 if (!it->isUnspecified())
495 std::vector<NodeHandle>::const_iterator i;
507 if (optimize) ret = &smallest;
508 else return smallest;
513 if (optimize) ret = &biggest;
523 std::vector<NodeHandle>::iterator i;
529 if (i ==
bigger) left =
false;
530 if ((! i->isUnspecified()) && (i->getIp() == failed.
getIp()))
break;
576 std::map<TransportAddress, PLSRepairData>::iterator it;
580 simtime_t now = simTime();
598 left = it->second.left;
605 EV <<
"[PastryLeafSet::repair()]\n"
606 <<
" LeafSet repair was successful."
613 EV <<
"[PastryLeafSet::repair()]\n"
614 <<
" LeafSet giving up repair attempt."
627 std::vector<NodeHandle>::const_iterator it;
647 std::vector<OverlayKey> temp;
648 for (uint8_t i = 0; i <
leaves.size() / 2; ++i) {
649 if (!
leaves[i].isUnspecified()) {
650 temp.push_back(
leaves[i].getKey());
654 for (uint8_t i =
leaves.size() / 2; i <
leaves.size(); ++i) {
655 if (!
leaves[i].isUnspecified()) {
656 temp.push_back(
leaves[i].getKey());
662 while (num < temp.size()) {
671 for (uint8_t i = 0; i < num; ++i) {
684 std::vector<NodeHandle> temp =
leaves;
689 if (!result)
return false;
692 const std::vector<NodeHandle>& current =
leaves;
695 for (std::vector<NodeHandle>::const_iterator it = temp.begin();
696 it != temp.end(); ++it) {
697 if (it->isUnspecified())
continue;
698 std::vector<NodeHandle>::const_iterator it2;
699 for (it2 = current.begin(); it2 != current.end(); ++it2) {
700 if (it2->isUnspecified())
continue;
701 if (*it2 == *it)
break;
703 if (it2 == current.end()) {
707 for (std::vector<NodeHandle>::const_iterator it = current.begin();
708 it != current.end(); ++it) {
709 if (it->isUnspecified())
continue;
710 std::vector<NodeHandle>::const_iterator it2;
711 for (it2 = temp.begin(); it2 != temp.end(); ++it2) {
712 if (it2->isUnspecified())
continue;
713 if (*it2 == *it)
break;
715 if (it2 == temp.end()) {