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 <deque>
00028 #include <omnetpp.h>
00029
00030 #include <CommonMessages_m.h>
00031 #include <BaseOverlay.h>
00032 #include <GlobalStatistics.h>
00033 #include <NeighborCache.h>
00034
00035 #include "KademliaNodeHandle.h"
00036 #include "KademliaBucket.h"
00037
00038
00061 class Kademlia : public BaseOverlay, public ProxListener
00062 {
00063 protected:
00064
00065 uint32_t k;
00066 uint32_t b;
00067 uint32_t s;
00068
00069 uint32_t maxStaleCount;
00070
00071
00072 bool exhaustiveRefresh;
00073 bool pingNewSiblings;
00074 bool secureMaintenance;
00075 bool newMaintenance;
00076
00077 bool enableReplacementCache;
00078 bool replacementCachePing;
00079 uint replacementCandidates;
00080 int siblingRefreshNodes;
00081 int bucketRefreshNodes;
00082
00083
00084 bool activePing;
00085 bool proximityRouting;
00086 bool proximityNeighborSelection;
00087 bool altRecMode;
00088
00089 simtime_t minSiblingTableRefreshInterval;
00090 simtime_t minBucketRefreshInterval;
00091 simtime_t siblingPingInterval;
00092
00093 cMessage* bucketRefreshTimer;
00094 cMessage* siblingPingTimer;
00095
00096 public:
00097 Kademlia();
00098
00099 ~Kademlia();
00100
00101 void initializeOverlay(int stage);
00102
00103 void finishOverlay();
00104
00105 void joinOverlay();
00106
00107 bool isSiblingFor(const NodeHandle& node,const OverlayKey& key,
00108 int numSiblings, bool* err );
00109
00110 int getMaxNumSiblings();
00111
00112 int getMaxNumRedundantNodes();
00113
00114 void handleTimerEvent(cMessage* msg);
00115
00116 bool handleRpcCall(BaseCallMessage* msg);
00117
00118 void handleUDPMessage(BaseOverlayMessage* msg);
00119
00120 virtual void proxCallback(const TransportAddress& node, int rpcId,
00121 cPolymorphic *contextPointer, Prox prox);
00122
00123 protected:
00124 NodeVector* findNode(const OverlayKey& key,
00125 int numRedundantNodes,
00126 int numSiblings,
00127 BaseOverlayMessage* msg);
00128
00129 void handleRpcResponse(BaseResponseMessage* msg,
00130 cPolymorphic* context,
00131 int rpcId, simtime_t rtt);
00132
00133 void handleRpcTimeout(BaseCallMessage* msg, const TransportAddress& dest,
00134 cPolymorphic* context, int rpcId,
00135 const OverlayKey& destKey);
00136
00140 void handleBucketRefreshTimerExpired();
00141
00142 OverlayKey distance(const OverlayKey& x,
00143 const OverlayKey& y,
00144 bool useAlternative = false) const;
00145
00149 void updateTooltip();
00150
00151 virtual void lookupFinished(bool isValid);
00152
00153 virtual void handleNodeGracefulLeaveNotification();
00154
00155 friend class KademliaLookupListener;
00156
00157
00158 private:
00159 uint32_t bucketRefreshCount;
00160 uint32_t siblingTableRefreshCount;
00161 uint32_t nodesReplaced;
00162
00163 KeyDistanceComparator<KeyXorMetric>* comparator;
00164
00165 KademliaBucket* siblingTable;
00166 std::vector<KademliaBucket*> routingTable;
00167 int numBuckets;
00168
00169 void routingInit();
00170
00171 void routingDeinit();
00172
00182 int routingBucketIndex(const OverlayKey& key, bool firstOnLayer = false);
00183
00194 KademliaBucket* routingBucket(const OverlayKey& key, bool ensure);
00195
00205 bool routingAdd(const NodeHandle& handle, bool isAlive,
00206 simtime_t rtt = MAXTIME, bool maintenanceLookup = false);
00207
00216 bool routingTimeout(const OverlayKey& key, bool immediately = false);
00217
00218 void refillSiblingTable();
00219
00220 void sendSiblingFindNodeCall(const TransportAddress& dest);
00221
00222 void setBucketUsage(const OverlayKey& key);
00223
00224 bool recursiveRoutingHook(const TransportAddress& dest,
00225 BaseRouteMessage* msg);
00226
00227 bool handleFailedNode(const TransportAddress& failed);
00228 };
00229
00230 #endif