KademliaNodeHandle.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 #ifndef __KADEMLIA_NODE_HANDLE_H
00019 #define __KADEMLIA_NODE_HANDLE_H
00020 
00021 #include <NodeHandle.h>
00022 #include <NodeVector.h>
00023 
00028 class KademliaBucketEntry : public NodeHandle
00029 {
00030 public:
00034     KademliaBucketEntry()
00035     : NodeHandle()
00036     {
00037         staleCount = 0;
00038         rtt = MAXTIME;
00039     }
00040 
00041     KademliaBucketEntry(const NodeHandle& handle, simtime_t rtt = MAXTIME)
00042     : NodeHandle(handle)
00043     {
00044         staleCount = 0;
00045         this->rtt = rtt;
00046     }
00047 
00055     KademliaBucketEntry(const OverlayKey& key,
00056                         const IPvXAddress& ip,
00057                         int port)
00058     : NodeHandle(key, ip, port)
00059     {
00060         staleCount = 0;
00061         rtt = MAXTIME;
00062     }
00063 
00064     inline simtime_t getRtt() const { return rtt; }
00065 
00066     inline void setRtt(simtime_t rtt) { this->rtt = rtt; }
00067 
00068     inline bool operator<(const KademliaBucketEntry& entry) const
00069     {
00070         return rtt < entry.rtt;
00071     }
00072 
00073     inline uint8_t getStaleCount() const { return staleCount; }
00074 
00075     inline void setStaleCount(uint8_t staleCount)
00076     {
00077         this->staleCount = staleCount;
00078     }
00079 
00080     inline void resetStaleCount() { this->setStaleCount(0); }
00081 
00082     inline void incStaleCount() { this->staleCount++; }
00083 
00084     inline void setLastSeen(simtime_t lastSeen) { this->lastSeen = lastSeen; }
00085 
00086     inline simtime_t getLastSeen() { return this->lastSeen; }
00087 
00088 private:
00089 
00090     uint8_t staleCount;
00091     simtime_t lastSeen;
00092     simtime_t rtt;
00093 
00094     friend std::ostream& operator<<(std::ostream& os,
00095                                     const KademliaBucketEntry& n)
00096     {
00097         os << (NodeHandle)n << " " << n.rtt;
00098         return os;
00099     };
00100 };
00101 
00109 template <> struct KeyExtractor<KademliaBucketEntry>
00110 {
00111     static const OverlayKey& key(const KademliaBucketEntry& entry)
00112     {
00113         return entry.key;
00114     };
00115 };
00116 
00117 template <> struct RttExtractor<KademliaBucketEntry>
00118 {
00119     static simtime_t rtt(const KademliaBucketEntry& entry)
00120     {
00121         return entry.getRtt();
00122     };
00123 };
00124 
00125 
00126 #endif

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