Kademlia.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #ifndef __KADEMLIA_H_
00025 #define __KADEMLIA_H_
00026
00027 #include <omnetpp.h>
00028
00029 #include <CommonMessages_m.h>
00030 #include <BaseOverlay.h>
00031 #include <GlobalStatistics.h>
00032 #include <NeighborCache.h>
00033
00034 #include "KademliaNodeHandle.h"
00035 #include "KademliaBucket.h"
00036
00042 class Kademlia : public BaseOverlay
00043 {
00044 protected:
00045
00046 uint32_t k;
00047 uint32_t b;
00048 uint32_t s;
00049
00050 uint32_t maxStaleCount;
00051
00052
00053 bool exhaustiveRefresh;
00054 bool pingNewSiblings;
00055
00056 simtime_t minSiblingTableRefreshInterval;
00057 simtime_t minBucketRefreshInterval;
00058
00059 cMessage* bucketRefreshTimer;
00060
00061 public:
00062 Kademlia();
00063
00064 ~Kademlia();
00065
00066 void initializeOverlay(int stage);
00067
00068 void finishOverlay();
00069
00070 void joinOverlay();
00071
00072 bool isSiblingFor(const NodeHandle& node,const OverlayKey& key,
00073 int numSiblings, bool* err );
00074
00075 int getMaxNumSiblings();
00076
00077 int getMaxNumRedundantNodes();
00078
00079 void handleTimerEvent(cMessage* msg);
00080
00081 bool handleRpcCall(BaseCallMessage* msg);
00082
00083 protected:
00084 NodeVector* findNode(const OverlayKey& key,
00085 int numRedundantNodes,
00086 int numSiblings,
00087 BaseOverlayMessage* msg);
00088
00089 void handleRpcResponse(BaseResponseMessage* msg,
00090 cPolymorphic* context,
00091 int rpcId, simtime_t rtt);
00092
00093 void handleRpcTimeout(BaseCallMessage* msg, const TransportAddress& dest,
00094 cPolymorphic* context, int rpcId,
00095 const OverlayKey& destKey);
00096
00100 void handleBucketRefreshTimerExpired();
00101
00102 OverlayKey distance(const OverlayKey& x,
00103 const OverlayKey& y) const;
00104
00108 void updateTooltip();
00109
00110 virtual void lookupFinished(bool isValid);
00111
00112 friend class KademliaLookupListener;
00113
00114
00115 private:
00116 uint32_t bucketRefreshCount;
00117 uint32_t siblingTableRefreshCount;
00118 uint32_t nodesReplaced;
00119
00120 KeyDistanceComparator<KeyXorMetric>* comparator;
00121
00122 KademliaBucket* siblingTable;
00123 std::vector<KademliaBucket*> routingTable;
00124 int numBuckets;
00125
00126 std::map<NodeHandle, NodeHandle> replacementCache;
00127 void routingInit();
00128
00129 void routingDeinit();
00130
00140 int routingBucketIndex(const OverlayKey& key, bool firstOnLayer = false);
00141
00152 KademliaBucket* routingBucket(const OverlayKey& key, bool ensure);
00153
00162 bool routingAdd(const NodeHandle& handle, bool isAlive,
00163 simtime_t rtt = MAXTIME);
00164
00171 bool routingRemove(const OverlayKey& key);
00172
00181 bool routingTimeout(const OverlayKey& key, bool immediately = false);
00182
00183 void refillSiblingTable();
00184
00185 void setBucketUsage(const OverlayKey& key);
00186
00187 bool handleFailedNode(const TransportAddress& failed);
00188 };
00189
00190 #endif