#include <RecursiveLookup.h>
Public Member Functions | |
RecursiveLookup (BaseOverlay *overlay) | |
virtual | ~RecursiveLookup () |
Virtual destructor. | |
virtual void | lookup (const OverlayKey &key, int numSiblings=1, int hopCountMax=0, int retries=0, LookupListener *listener=NULL) |
Lookup siblings for a key. | |
virtual const NodeVector & | getResult () const |
Returns the result of the lookup. | |
virtual bool | isValid () const |
Returns true, if the lookup was successful. | |
virtual void | abortLookup () |
Aborts a running lookup. | |
virtual uint | getAccumulatedHops () const |
Returns the total number of hops for all lookup paths. | |
void | handleRpcTimeout (BaseCallMessage *msg, const TransportAddress &dest, int rpcId, const OverlayKey &destKey) |
This method is called if an RPC timeout has been reached. | |
void | handleRpcResponse (BaseResponseMessage *msg, int rpcId, simtime_t rtt) |
This method is called if an RPC response has been received. | |
Private Attributes | |
BaseOverlay * | overlay |
LookupListener * | listener |
uint32_t | nonce |
bool | valid |
NodeVector | siblings |
RecursiveLookup::RecursiveLookup | ( | BaseOverlay * | overlay | ) |
RecursiveLookup::~RecursiveLookup | ( | ) | [virtual] |
void RecursiveLookup::lookup | ( | const OverlayKey & | key, | |
int | numSiblings = 1 , |
|||
int | hopCountMax = 0 , |
|||
int | retries = 0 , |
|||
LookupListener * | listener = NULL | |||
) | [virtual] |
Lookup siblings for a key.
key | The key to lookup | |
numSiblings | Number of siblings to lookup | |
hopCountMax | Maximum hop count | |
retries | Number of retries if lookup fails | |
listener | Listener to inform, when the lookup is done |
Implements AbstractLookup.
00041 { 00042 this->listener = listener; 00043 00044 FindNodeCall* call = new FindNodeCall("FindNodeCall"); 00045 call->setLookupKey(key); 00046 call->setNumRedundantNodes(0); 00047 call->setNumSiblings(numSiblings); 00048 call->setLength(FINDNODECALL_L(call)); 00049 00050 nonce = overlay->sendRouteRpcCall(OVERLAY_COMP, key, call, 00051 -1, retries, -1, this); 00052 }
const NodeVector & RecursiveLookup::getResult | ( | ) | const [virtual] |
Returns the result of the lookup.
Implements AbstractLookup.
00055 { 00056 return siblings; 00057 }
bool RecursiveLookup::isValid | ( | ) | const [virtual] |
Returns true, if the lookup was successful.
Implements AbstractLookup.
00060 { 00061 return valid; 00062 }
void RecursiveLookup::abortLookup | ( | ) | [virtual] |
Aborts a running lookup.
This method aborts a running lookup without calling the listener and delete the lookup object.
Implements AbstractLookup.
00065 { 00066 overlay->cancelRpcMessage(nonce); 00067 00068 if (listener != NULL) { 00069 delete listener; 00070 listener = NULL; 00071 } 00072 00073 delete this; 00074 }
uint RecursiveLookup::getAccumulatedHops | ( | ) | const [virtual] |
Returns the total number of hops for all lookup paths.
Implements AbstractLookup.
void RecursiveLookup::handleRpcTimeout | ( | BaseCallMessage * | msg, | |
const TransportAddress & | dest, | |||
int | rpcId, | |||
const OverlayKey & | destKey | |||
) | [virtual] |
This method is called if an RPC timeout has been reached.
msg | The original RPC message. | |
dest | The destination node | |
rpcId | The RPC id. | |
destKey | the destination OverlayKey |
Reimplemented from RpcListener.
00084 { 00085 valid = false; 00086 }
void RecursiveLookup::handleRpcResponse | ( | BaseResponseMessage * | msg, | |
int | rpcId, | |||
simtime_t | rtt | |||
) | [virtual] |
This method is called if an RPC response has been received.
msg | The response message. | |
rpcId | The RPC id. | |
rtt | The Round-Trip-Time of this RPC |
Reimplemented from RpcListener.
00090 { 00091 FindNodeResponse* findNodeResponse = check_and_cast<FindNodeResponse*>(msg); 00092 00093 if (findNodeResponse->getSiblings() && 00094 findNodeResponse->getClosestNodesArraySize() > 0) { 00095 valid = true; 00096 for (uint i = 0; i < findNodeResponse->getClosestNodesArraySize(); 00097 i++) { 00098 siblings.push_back(findNodeResponse->getClosestNodes(i)); 00099 } 00100 } 00101 00102 // inform listener 00103 if (listener != NULL) { 00104 listener->lookupFinished(this); 00105 listener = NULL; 00106 } 00107 }
BaseOverlay* RecursiveLookup::overlay [private] |
LookupListener* RecursiveLookup::listener [private] |
uint32_t RecursiveLookup::nonce [private] |
bool RecursiveLookup::valid [private] |
NodeVector RecursiveLookup::siblings [private] |