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 <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
00044 class Kademlia : public BaseOverlay
00045 {
00046 protected:
00047
00048 uint32_t k;
00049 uint32_t b;
00050 uint32_t s;
00051
00052 uint32_t maxStaleCount;
00053
00054
00055 bool exhaustiveRefresh;
00056 bool pingNewSiblings;
00057 bool secureMaintenance;
00058 bool newMaintenance;
00059
00060 bool enableReplacementCache;
00061 bool replacementCachePing;
00062 uint replacementCandidates;
00063 int siblingRefreshNodes;
00064 int bucketRefreshNodes;
00065
00066 simtime_t minSiblingTableRefreshInterval;
00067 simtime_t minBucketRefreshInterval;
00068 simtime_t siblingPingInterval;
00069
00070 cMessage* bucketRefreshTimer;
00071 cMessage* siblingPingTimer;
00072
00073 public:
00074 Kademlia();
00075
00076 ~Kademlia();
00077
00078 void initializeOverlay(int stage);
00079
00080 void finishOverlay();
00081
00082 void joinOverlay();
00083
00084 bool isSiblingFor(const NodeHandle& node,const OverlayKey& key,
00085 int numSiblings, bool* err );
00086
00087 int getMaxNumSiblings();
00088
00089 int getMaxNumRedundantNodes();
00090
00091 void handleTimerEvent(cMessage* msg);
00092
00093 bool handleRpcCall(BaseCallMessage* msg);
00094
00095 protected:
00096 NodeVector* findNode(const OverlayKey& key,
00097 int numRedundantNodes,
00098 int numSiblings,
00099 BaseOverlayMessage* msg);
00100
00101 void handleRpcResponse(BaseResponseMessage* msg,
00102 cPolymorphic* context,
00103 int rpcId, simtime_t rtt);
00104
00105 void handleRpcTimeout(BaseCallMessage* msg, const TransportAddress& dest,
00106 cPolymorphic* context, int rpcId,
00107 const OverlayKey& destKey);
00108
00112 void handleBucketRefreshTimerExpired();
00113
00114 OverlayKey distance(const OverlayKey& x,
00115 const OverlayKey& y,
00116 bool useAlternative = false) const;
00117
00121 void updateTooltip();
00122
00123 virtual void lookupFinished(bool isValid);
00124
00125 virtual void handleNodeGracefulLeaveNotification();
00126
00127 friend class KademliaLookupListener;
00128
00129
00130 private:
00131 uint32_t bucketRefreshCount;
00132 uint32_t siblingTableRefreshCount;
00133 uint32_t nodesReplaced;
00134
00135 KeyDistanceComparator<KeyXorMetric>* comparator;
00136
00137 KademliaBucket* siblingTable;
00138 std::vector<KademliaBucket*> routingTable;
00139 int numBuckets;
00140
00141 void routingInit();
00142
00143 void routingDeinit();
00144
00154 int routingBucketIndex(const OverlayKey& key, bool firstOnLayer = false);
00155
00166 KademliaBucket* routingBucket(const OverlayKey& key, bool ensure);
00167
00177 bool routingAdd(const NodeHandle& handle, bool isAlive,
00178 simtime_t rtt = MAXTIME, bool maintenanceLookup = false);
00179
00188 bool routingTimeout(const OverlayKey& key, bool immediately = false);
00189
00190 void refillSiblingTable();
00191
00192 void sendSiblingFindNodeCall(const TransportAddress& dest);
00193
00194 void setBucketUsage(const OverlayKey& key);
00195
00196 bool handleFailedNode(const TransportAddress& failed);
00197 };
00198
00199 #endif