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         pingSent = false;
00039     }
00040 
00041     KademliaBucketEntry(const NodeHandle& handle, simtime_t prox = MAXTIME)
00042     : ProxNodeHandle(handle)
00043     {
00044         staleCount = 0;
00045         this->prox.proximity = SIMTIME_DBL(prox);
00046         this->prox.accuracy = 1.0;
00047         pingSent = false;
00048     }
00049 
00050     // TODO
00051     inline simtime_t getRtt() const { return getProx(); } //deprecated
00052     inline void setRtt(simtime_t rtt) { this->prox.proximity = SIMTIME_DBL(rtt);  this->prox.accuracy = 1; } //deprecated
00053 
00054     inline uint8_t getStaleCount() const { return staleCount; }
00055 
00056     inline void setStaleCount(uint8_t staleCount) { this->staleCount = staleCount; }
00057 
00058     inline void resetStaleCount() { this->setStaleCount(0); }
00059 
00060     inline void incStaleCount() { this->staleCount++; }
00061 
00062     inline void setLastSeen(simtime_t lastSeen) { this->lastSeen = lastSeen; }
00063 
00064     inline simtime_t getLastSeen() { return this->lastSeen; }
00065 
00066     inline void setPingSent(bool pingSent) { this->pingSent = pingSent; }
00067 
00068     inline bool getPingSent() const { return pingSent; };
00069 
00070 private:
00071 
00072     uint8_t staleCount;
00073     simtime_t lastSeen;
00074     bool pingSent; /*< true, if there is a pending pong for this node */
00075 
00076     friend std::ostream& operator<<(std::ostream& os,
00077                                     const KademliaBucketEntry& n)
00078     {
00079         os << (NodeHandle)n << " " << n.prox.proximity;
00080         return os;
00081     };
00082 };
00083 
00091 template <> struct KeyExtractor<KademliaBucketEntry>
00092 {
00093     static const OverlayKey& key(const KademliaBucketEntry& entry)
00094     {
00095         return entry.getKey();
00096     };
00097 };
00098 
00099 template <> struct ProxExtractor<KademliaBucketEntry>
00100 {
00101     static Prox prox(const KademliaBucketEntry& entry)
00102     {
00103         return entry.getProx();
00104     };
00105 };
00106 
00107 
00108 #endif
Generated on Wed May 26 16:21:14 2010 for OverSim by  doxygen 1.6.3