KademliaNodeHandle.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2009 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 ProxNodeHandle
00029 {
00030 public:
00034     KademliaBucketEntry()
00035     : ProxNodeHandle()
00036     {
00037         staleCount = 0;
00038     }
00039 
00040     KademliaBucketEntry(const NodeHandle& handle, simtime_t prox = MAXTIME)
00041     : ProxNodeHandle(handle)
00042     {
00043         staleCount = 0;
00044         this->prox.proximity = SIMTIME_DBL(prox);
00045         this->prox.accuracy = 1.0;
00046     }
00047 
00055     KademliaBucketEntry(const OverlayKey& key,
00056                         const IPvXAddress& ip,
00057                         int port)
00058     : ProxNodeHandle(NodeHandle(key, ip, port))
00059     {
00060         staleCount = 0;
00061     }
00062 
00063     // TODO
00064     inline simtime_t getRtt() const { return getProx(); } //deprecated
00065     inline void setRtt(simtime_t rtt) { this->prox.proximity = SIMTIME_DBL(rtt);  this->prox.accuracy = 1; } //deprecated
00066 
00067     inline uint8_t getStaleCount() const { return staleCount; }
00068 
00069     inline void setStaleCount(uint8_t staleCount) { this->staleCount = staleCount; }
00070 
00071     inline void resetStaleCount() { this->setStaleCount(0); }
00072 
00073     inline void incStaleCount() { this->staleCount++; }
00074 
00075     inline void setLastSeen(simtime_t lastSeen) { this->lastSeen = lastSeen; }
00076 
00077     inline simtime_t getLastSeen() { return this->lastSeen; }
00078 
00079 private:
00080 
00081     uint8_t staleCount;
00082     simtime_t lastSeen;
00083 
00084     friend std::ostream& operator<<(std::ostream& os,
00085                                     const KademliaBucketEntry& n)
00086     {
00087         os << (NodeHandle)n << " " << n.prox.proximity;
00088         return os;
00089     };
00090 };
00091 
00099 template <> struct KeyExtractor<KademliaBucketEntry>
00100 {
00101     static const OverlayKey& key(const KademliaBucketEntry& entry)
00102     {
00103         return entry.getKey();
00104     };
00105 };
00106 
00107 template <> struct ProxExtractor<KademliaBucketEntry>
00108 {
00109     static Prox prox(const KademliaBucketEntry& entry)
00110     {
00111         return entry.getProx();
00112     };
00113 };
00114 
00115 
00116 #endif

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