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 #include <NeighborCache.h>
00033 
00034 #include "KademliaNodeHandle.h"
00035 #include "KademliaBucket.h"
00036 
00042 class Kademlia : public BaseOverlay
00043 {
00044 protected://fields: kademlia parameters
00045 
00046     uint32_t k; /*< number of redundant graphs */
00047     uint32_t b; /*< number of bits to consider */
00048     uint32_t s; /*< number of siblings         */
00049 
00050     uint32_t maxStaleCount; /*< number of timouts until node is removed from
00051                             routingtable */
00052 
00053     bool exhaustiveRefresh; /*< if true, use exhaustive-iterative lookups to refresh buckets */
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; /*< statistics: total number of bucket refreshes */
00117     uint32_t siblingTableRefreshCount; /*< statistics: total number of sibling table refreshes */
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

Generated on Tue Sep 8 17:26:53 2009 for OverSim by  doxygen 1.5.8