00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #ifndef __DHTDATASTORAGE_H_
00025 #define __DHTDATASTORAGE_H_
00026
00027 #include <set>
00028 #include <vector>
00029 #include <sstream>
00030
00031 #include <omnetpp.h>
00032
00033 #include <NodeHandle.h>
00034 #include <InitStages.h>
00035 #include <BinaryValue.h>
00036
00047 struct DHTData
00048 {
00049 BinaryValue value;
00050 cMessage* ttlMessage;
00051 bool is_modifiable;
00052 NodeHandle sourceNode;
00053 bool responsible;
00054 friend std::ostream& operator<<(std::ostream& Stream, const DHTData entry);
00055 };
00056
00057 struct DhtDumpEntry
00058 {
00059 OverlayKey key;
00060 BinaryValue value;
00061 int ttl;
00062 NodeHandle owner;
00063 bool is_modifiable;
00064 bool responsible;
00065 };
00066
00067 typedef std::vector<DhtDumpEntry> DhtDumpVector;
00068
00069 typedef std::vector<std::pair<OverlayKey, DHTData> > DhtDataVector;
00070
00071 class DHTDataStorage : public cSimpleModule
00072 {
00073 public:
00074 virtual int numInitStages() const
00075 {
00076 return MAX_STAGE_APP + 1;
00077 }
00078 virtual void initialize(int stage);
00079 virtual void handleMessage(cMessage* msg);
00080
00086 virtual uint32_t getSize();
00087
00091 virtual void clear();
00092
00098 virtual bool isEmpty();
00099
00106 virtual const BinaryValue& getData(const OverlayKey& key);
00107
00114 virtual const NodeHandle& getSourceNode(const OverlayKey& key);
00115
00122 virtual cMessage* getTtlMessage(const OverlayKey& key);
00123
00130 virtual const bool isModifiable(const OverlayKey& key);
00131
00132
00139 virtual const BinaryValue& getDataAtPos(uint32_t pos = 0);
00140
00146 virtual const std::map<OverlayKey, DHTData>::iterator begin();
00147
00158 virtual void addData(OverlayKey key, BinaryValue value, cMessage* ttlMessage, bool is_modifiable=true, NodeHandle sourceNode=NodeHandle::UNSPECIFIED_NODE, bool responsible=true);
00159
00165 virtual void removeData(OverlayKey key);
00166 void display ();
00167
00173 DhtDataVector* get_range(const OverlayKey lkey, const OverlayKey rkey);
00174
00180 DhtDumpVector* dumpDht();
00181
00182 protected:
00183 std::map<OverlayKey, DHTData> dataMap;
00188 void updateDisplayString();
00189
00193 void updateTooltip();
00194 };
00195
00196 #endif