DHTDataStorage.h
Go to the documentation of this file.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 <map>
00030 #include <sstream>
00031
00032 #include <omnetpp.h>
00033
00034 #include <NodeHandle.h>
00035 #include <InitStages.h>
00036 #include <BinaryValue.h>
00037 #include <NodeVector.h>
00038 #include <CommonMessages_m.h>
00039
00049 typedef std::map<BinaryValue, NodeVector> SiblingVoteMap;
00050
00051 struct DhtDataEntry
00052 {
00053 BinaryValue value;
00054 uint32_t kind;
00055 uint32_t id;
00056 cMessage* ttlMessage;
00057 bool is_modifiable;
00058 NodeHandle sourceNode;
00059 bool responsible;
00060 friend std::ostream& operator<<(std::ostream& Stream, const DhtDataEntry entry);
00061 SiblingVoteMap siblingVote;
00062 };
00063
00064 typedef std::vector<std::pair<OverlayKey, DhtDataEntry> > DhtDataVector;
00065 typedef std::vector<DhtDumpEntry> DhtDumpVector;
00066 typedef std::multimap<OverlayKey, DhtDataEntry> DhtDataMap;
00067
00068 class DHTDataStorage : public cSimpleModule
00069 {
00070 public:
00071
00072 virtual int numInitStages() const
00073 {
00074 return MAX_STAGE_APP + 1;
00075 }
00076 virtual void initialize(int stage);
00077 virtual void handleMessage(cMessage* msg);
00078
00084 virtual uint32_t getSize();
00085
00089 virtual void clear();
00090
00100 DhtDataEntry* getDataEntry(const OverlayKey& key,
00101 uint32_t kind, uint32_t id);
00102
00103
00113 virtual DhtDataVector* getDataVector(const OverlayKey& key,
00114 uint32_t kind = 0,
00115 uint32_t id = 0);
00116
00126 virtual const NodeHandle& getSourceNode(const OverlayKey& key,
00127 uint32_t kind, uint32_t id);
00128
00137 virtual const bool isModifiable(const OverlayKey& key,
00138 uint32_t kind, uint32_t id);
00139
00145 virtual const DhtDataMap::iterator begin();
00146
00152 virtual const DhtDataMap::iterator end();
00153
00154
00167 virtual DhtDataEntry* addData(const OverlayKey& key, uint32_t kind,
00168 uint32_t id,
00169 BinaryValue value, cMessage* ttlMessage,
00170 bool is_modifiable=true,
00171 NodeHandle sourceNode=NodeHandle::UNSPECIFIED_NODE,
00172 bool responsible=true);
00173
00182 virtual void removeData(const OverlayKey& key, uint32_t kind, uint32_t id);
00183
00184 void display();
00185
00195 DhtDumpVector* dumpDht(const OverlayKey& key = OverlayKey::UNSPECIFIED_KEY,
00196 uint32_t kind = 0, uint32_t id = 0);
00197
00198 protected:
00199 DhtDataMap dataMap;
00204 void updateDisplayString();
00205
00209 void updateTooltip();
00210 };
00211
00212 #endif