69 return *((
rows.begin()+row)->begin()+col);
75 if (destination ==
owner.
getKey()) opp_error(
"trying to lookup own key!");
78 uint32_t digit =
digitAt(shl, destination);
80 if (shl >=
rows.size()) {
81 EV <<
"Pastry: Unable to find next hop for " << destination
82 <<
", row is empty." << endl;
89 EV <<
"Pastry: Unable to find next hop for " << destination
90 <<
", routing table entry is empty." << endl;
100 opp_error(
"trying to find closer node to own key!");
114 int digit =
digitAt(shl, destination);
122 while ((a >= 0) || (b < n)) {
129 entry = &(
nodeAt(shl, a));
132 ret = &(entry->
node);
136 entry = &(
nodeAt(shl, b));
139 ret = &(entry->
node);
150 entry = &(
nodeAt(shl, digit - 1));
153 ret = &(entry->
node);
155 entry = &(
nodeAt(shl, digit + 1));
158 ret = &(entry->
node);
165 for (uint32_t y = 0; y <
rows.size(); ++y) {
185 for (uint32_t y = 0; y <
rows.size(); ++y) {
200 std::vector<PRTRow>::const_iterator itRows;
201 PRTRow::const_iterator itCols;
205 for (itRows =
rows.begin(); itRows !=
rows.end(); itRows++) {
206 for (itCols = itRows->begin(); itCols != itRows->end(); itCols++) {
207 if (!itCols->node.isUnspecified()) {
222 std::vector<PRTRow>::const_iterator itRows;
223 PRTRow::const_iterator itCols;
226 if ((row == -1) || (row > (
int)
rows.size())) {
227 itRows =
rows.end() - 1;
228 }
else if (row > (
int)
rows.size()) {
229 EV <<
"asked for nonexistent row";
234 itRows =
rows.begin() + row - 1;
236 for (itCols = itRows->begin(); itCols != itRows->end(); itCols++) {
237 if (!itCols->node.isUnspecified()) {
249 std::vector<TransportAddress>* temp =
new std::vector<TransportAddress>;
250 if ((row < 1) || (row > (
int)
rows.size()))
return temp;
252 std::vector<PRTRow>::const_iterator itRows =
rows.begin() + row - 1;
254 for (PRTRow::const_iterator itCols = itRows->begin();
255 itCols != itRows->end(); ++itCols) {
256 if (itCols != itRows->end() && !itCols->node.isUnspecified()) {
257 temp->push_back(itCols->node);
272 std::vector<PRTRow>::const_iterator itRows;
273 PRTRow::const_iterator itCols;
276 itRows =
rows.begin() + row;
277 if (itRows >=
rows.end()) {
278 EV <<
"[PastryRoutingTable::getRandomNode()]\n"
279 <<
" tried to get random Node from nonexistent row"
283 itCols = itRows->begin() + rnd;
284 while (itCols != itRows->end()) {
285 if (!itCols->node.isUnspecified())
return itCols->node;
288 itCols = itRows->begin() + rnd;
289 while (itCols >= itRows->begin()) {
290 if (!itCols->node.isUnspecified())
return itCols->node;
300 opp_error(
"trying to merge node with same key!");
304 PRTRow::iterator position;
310 position = (
rows.begin() + shl)->begin() + digit;
311 if (position->node.isUnspecified() || (prox < position->rtt)) {
312 EV <<
"[PastryRoutingTable::mergeNode()]\n"
315 EV <<
" placing node " << node.
getKey() <<
"in row "
316 << shl <<
", col" << digit << endl;
317 if (! position->node.isUnspecified()) {
318 EV <<
" (replaced because of better proximity: "
319 << prox <<
" < " << position->rtt <<
")" << endl;
321 position->node = node;
322 position->rtt = prox;
331 std::vector<PastryStateMsgHandle>::const_iterator it;
334 for (it = handles.begin(); it != handles.end(); ++it) {
335 if (it->msg->getRow() != ++hopCheck)
return false;
344 std::vector<PRTRow>::const_iterator itRows;
345 PRTRow::const_iterator itCols;
347 for (itRows =
rows.begin(); itRows !=
rows.end(); ++itRows)
348 for (itCols = itRows->begin(); itCols != itRows->end(); ++itCols)
349 if (!itCols->node.isUnspecified())
350 affected.push_back(itCols->node);
366 os <<
"Pastry IRoutingTable row {" << endl;
367 for (PRTRow::const_iterator i = row.begin(); i != row.end(); i++) {
368 os <<
" " << i->node <<
" ; Ping: ";
369 if (i->rtt != SimTime::getMaxTime())
370 os << i->rtt << endl;
371 else os <<
"<unknown>" << endl;
380 std::vector<PRTRow>::iterator itRows;
381 PRTRow::iterator itCols;
387 for (itRows =
rows.begin(); itRows !=
rows.end(); itRows++) {
388 for (itCols = itRows->begin(); itCols != itRows->end(); itCols++) {
389 if ((! itCols->node.isUnspecified()) &&
390 (itCols->node.getIp() == failed.
getIp())) {
405 tmpTrack.
failedCol = itCols - itRows->begin();
420 std::vector<PRTTrackRepair>::iterator it;
421 simtime_t now = simTime();
447 if (it->node.isUnspecified()) {
449 EV <<
"[PastryRoutingTable::repair()]\n"
450 <<
" RoutingTable giving up repair attempt."
455 else return it->node;
459 EV <<
"[PastryRoutingTable::repair()]\n"
460 <<
" RoutingTable repair was successful."