BasePathLookup Class Reference

#include <BaseLookup.h>

List of all members.


Detailed Description

This class implements a path lookup.

Author:
Sebastian Mies


Protected Member Functions

bool accepts (int rpcId)
void handleResponse (FindNodeResponse *msg)
void handleTimeout (int rpcId)
 BasePathLookup (BaseLookup *lookup)
virtual ~BasePathLookup ()
virtual FindNodeCallcreateRpcMessage (cObject *findNodeExt=NULL)
 Creates a find node call message.
void add (const NodeHandle &handle)
 Adds a NodeHandle to next hops.

Protected Attributes

BaseLookuplookup
int hops
int step
int pendingRpcs
bool finished
bool success
NodeVector nextHops

Private Member Functions

void sendRpc (int num, cObject *FindNodeExt=NULL)

Friends

class BaseLookup


Constructor & Destructor Documentation

BasePathLookup::BasePathLookup ( BaseLookup lookup  )  [protected]

00395 {
00396     this->lookup = lookup;
00397     this->hops = 0;
00398     this->step = 0;
00399     this->pendingRpcs = 0;
00400     this->finished = false;
00401     this->success = false;
00402     this->nextHops = NodeVector( lookup->config.numNextHops, lookup );
00403 }

BasePathLookup::~BasePathLookup (  )  [protected, virtual]

00406 {}


Member Function Documentation

bool BasePathLookup::accepts ( int  rpcId  )  [protected]

00409 {
00410     bool accept = ( rpcId == step ) && !finished;
00411     return accept;
00412 }

void BasePathLookup::add ( const NodeHandle handle  )  [protected]

Adds a NodeHandle to next hops.

00536 {
00537     if ( lookup->config.merge )
00538         nextHops.add(handle);
00539     else
00540         nextHops.push_back(handle);
00541 }

FindNodeCall * BasePathLookup::createRpcMessage ( cObject *  findNodeExt = NULL  )  [protected, virtual]

Creates a find node call message.

This method can be overridden to add some additional state information to the FindNodeCall message.

Parameters:
findNodeExt Pointer to a optional cObject, that may contain overlay specific data to be attached to FindNode RPCs and BaseRouteMessages
Returns:
Pointer to a new FindNodeCall message.
00521 {
00522     // create default find node call message
00523     FindNodeCall* call = new FindNodeCall( "FindNodeCall" );
00524     call->setLookupKey( lookup->key );
00525     call->setLength( FINDNODECALL_L(call) );
00526 
00527     // duplicate extension object
00528     if ( findNodeExt != NULL )
00529         call->addObject( (cObject*)findNodeExt->dup() );
00530 
00531     return call;
00532 }

void BasePathLookup::handleResponse ( FindNodeResponse msg  )  [protected]

00415 {
00416     if (finished)
00417         return;
00418 
00419     // increase hops: FIXME don't count local hops
00420     if (lookup->overlay->getThisNode() != msg->getSrcNode())
00421         hops++;
00422     step++;
00423 
00424     // decrease pending rpcs
00425     pendingRpcs--;
00426 
00427     // mode: merge or replace
00428     if ( !lookup->config.merge )
00429         nextHops.clear();
00430 
00431     // add new next hops
00432     for ( uint i=0; i < msg->getClosestNodesArraySize(); i++ ) {
00433         const NodeHandle& handle = msg->getClosestNodes(i);
00434 
00435         // add node handles to next hops and neighborhood
00436         add
00437             ( handle );
00438         if (!lookup->config.secure)
00439             lookup->addNeighbor( handle );
00440 
00441         // check if node was found
00442         if ( handle.key == lookup->key && !lookup->config.secure ) {
00443             finished = true;
00444             success = true;
00445             return;
00446         }
00447     }
00448 
00449     // check if neighborlookup is finished
00450     if ( msg->getNeighbors() && msg->getClosestNodesArraySize() != 0 &&
00451             lookup->numNeighbors != 0 && !lookup->config.secure ) {
00452 
00453         finished = true;
00454         success = true;
00455         return;
00456     }
00457 
00458     // extract find node extension object
00459     cObject* findNodeExt = NULL;
00460     if (msg->hasObject("findNodeExt"))
00461         findNodeExt = (msg->removeObject("findNodeExt"));
00462 
00463     // send next rpcs
00464     sendRpc( lookup->config.parallelRpcs, findNodeExt );
00465 
00466     // ...
00467     delete findNodeExt;
00468 }

void BasePathLookup::handleTimeout ( int  rpcId  )  [protected]

00472 {
00473     if (finished)
00474         return;
00475 
00476     EV << "BasePathLookup: Timeout of RPC " << rpcId << endl;
00477 
00478     // decrease pending rpcs
00479     pendingRpcs--;
00480 
00481     // last rpc? yes-> send next rpc
00482     if ( pendingRpcs == 0 )
00483         sendRpc( 1 );
00484 }

void BasePathLookup::sendRpc ( int  num,
cObject *  FindNodeExt = NULL 
) [private]

00488 {
00489     // path finished? yes -> quit
00490     if (finished)
00491         return;
00492 
00493     // send rpc messages
00494     while ( num >= 0 && nextHops.size() != 0 ) {
00495 
00496         // get top node handle
00497         const NodeHandle& handle = nextHops.front();
00498 
00499         // check if node has already been visited? no ->
00500         if ( !lookup->getVisited( handle ) ) {
00501 
00502             // send rpc to node increase pending rpcs
00503             pendingRpcs++;
00504             num--;
00505             lookup->sendRpc( handle, createRpcMessage( findNodeExt ),
00506                              this, step );
00507         }
00508 
00509         // delete first element and continue
00510         nextHops.erase( nextHops.begin() );
00511     }
00512 
00513     // no rpc sent and no pending rpcs? -> failed
00514     if ( pendingRpcs == 0 ) {
00515         finished = true;
00516         success = false;
00517     }
00518 }


Friends And Related Function Documentation

friend class BaseLookup [friend]


Member Data Documentation

bool BasePathLookup::finished [protected]

int BasePathLookup::hops [protected]

BaseLookup* BasePathLookup::lookup [protected]

NodeVector BasePathLookup::nextHops [protected]

int BasePathLookup::pendingRpcs [protected]

int BasePathLookup::step [protected]

bool BasePathLookup::success [protected]


The documentation for this class was generated from the following files:
Generated on Fri Dec 15 17:50:30 2006 for ITM OverSim by  doxygen 1.4.7