Kademlia.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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 
00033 #include "KademliaNodeHandle.h"
00034 #include "KademliaBucket.h"
00035 
00041 class Kademlia : public BaseOverlay {
00042 protected://fields: kademlia parameters
00043 
00044     uint32_t k; /*< number of redundant graphs */
00045     uint32_t b; /*< number of bits to consider */
00046     uint32_t s; /*< number of siblings         */
00047     //uint r; /*< number of replicas         */
00048 
00049     uint32_t maxStaleCount; /*< number of timouts until node is removed from
00050                             routingtable */
00051 
00052     bool pingNewSiblings;
00053 
00054     simtime_t minSiblingTableRefreshInterval;
00055     simtime_t minBucketRefreshInterval;
00056 
00057     cMessage* bucketRefreshTimer;
00058 
00059 public:
00060     Kademlia();
00061 
00062     ~Kademlia();
00063 
00064     void initializeOverlay(int stage);
00065 
00066     void finishOverlay();
00067 
00068     void joinOverlay();
00069 
00070     bool isSiblingFor( const NodeHandle& node,const OverlayKey& key,
00071                         int numSiblings, bool* err );
00072 
00073     int getMaxNumSiblings();
00074 
00075     int getMaxNumRedundantNodes();
00076 
00077     void handleTimerEvent(cMessage* msg);
00078 
00079     bool handleRpc( BaseCallMessage* msg );
00080 
00081 protected:
00082     NodeVector* findNode(const OverlayKey& key,
00083                          int numRedundantNodes,
00084                          int numSiblings,
00085                          BaseOverlayMessage* msg);
00086 
00087     void handleRpcResponse(BaseResponseMessage* msg,
00088                            cPolymorphic* context,
00089                            int rpcId, simtime_t rtt);
00090 
00091     void handleRpcTimeout(BaseCallMessage* msg, const TransportAddress& dest,
00092                           cPolymorphic* context, int rpcId,
00093                           const OverlayKey& destKey);
00094 
00098     //void handleStabilizeTimerExpired();
00099 
00103     void handleBucketRefreshTimerExpired();
00104 
00105     OverlayKey distance( const OverlayKey& x, const OverlayKey& y ) const;
00106 
00110     void updateTooltip();
00111 
00112     virtual void lookupFinished(bool isValid);
00113 
00114     friend class KademliaLookupListener;
00115 
00116     uint32_t nodesReplaced;
00117 
00118 private:
00119     KeyDistanceComparator<KeyXorMetric>* comparator;
00120 
00121     KademliaBucket*  siblingTable;
00122     std::vector<KademliaBucket*> routingTable;
00123     int numBuckets;
00124 
00125     std::map<NodeHandle, NodeHandle> replacementCache;
00126     void routingInit();
00127 
00128     void routingDeinit();
00129 
00139     int routingBucketIndex(const OverlayKey& key, bool firstOnLayer = false);
00140 
00151     KademliaBucket* routingBucket( const OverlayKey& key, bool ensure );
00152 
00161     bool routingAdd(const NodeHandle& handle, bool isAlive,
00162                     simtime_t rtt = MAXTIME);
00163 
00170     bool routingRemove( const OverlayKey& key );
00171 
00180     bool routingTimeout( const OverlayKey& key, bool immediately = false );
00181 
00182     void refillSiblingTable();
00183 
00184     void setBucketUsage(const OverlayKey& key);
00185 
00186 
00187     bool handleFailedNode(const TransportAddress& failed);
00188 };
00189 
00190 #endif

Generated on Wed Mar 25 16:32:49 2009 for OverSim by  doxygen 1.5.5