OverSim
DHTDataStorage.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #ifndef __DHTDATASTORAGE_H_
25 #define __DHTDATASTORAGE_H_
26 
27 #include <set>
28 #include <vector>
29 #include <map>
30 #include <sstream>
31 
32 #include <omnetpp.h>
33 
34 #include <NodeHandle.h>
35 #include <InitStages.h>
36 #include <BinaryValue.h>
37 #include <NodeVector.h>
38 #include <CommonMessages_m.h>
39 
49 typedef std::map<BinaryValue, NodeVector> SiblingVoteMap;
50 
52 {
54  uint32_t kind;
55  uint32_t id;
56  cMessage* ttlMessage;
59  bool responsible; //is this node responsible for this key ?
60  friend std::ostream& operator<<(std::ostream& Stream, const DhtDataEntry entry);
62 };
63 
64 typedef std::vector<std::pair<OverlayKey, DhtDataEntry> > DhtDataVector;
65 typedef std::vector<DhtDumpEntry> DhtDumpVector;
66 typedef std::multimap<OverlayKey, DhtDataEntry> DhtDataMap;
67 
68 class DHTDataStorage : public cSimpleModule
69 {
70  public:
71 
72  virtual int numInitStages() const
73  {
74  return MAX_STAGE_APP + 1;
75  }
76  virtual void initialize(int stage);
77  virtual void handleMessage(cMessage* msg);
78 
84  virtual uint32_t getSize();
85 
89  virtual void clear();
90 
101  uint32_t kind, uint32_t id);
102 
103 
113  virtual DhtDataVector* getDataVector(const OverlayKey& key,
114  uint32_t kind = 0,
115  uint32_t id = 0);
116 
126  virtual const NodeHandle& getSourceNode(const OverlayKey& key,
127  uint32_t kind, uint32_t id);
128 
137  virtual const bool isModifiable(const OverlayKey& key,
138  uint32_t kind, uint32_t id);
139 
145  virtual const DhtDataMap::iterator begin();
146 
152  virtual const DhtDataMap::iterator end();
153 
154 
167  virtual DhtDataEntry* addData(const OverlayKey& key, uint32_t kind,
168  uint32_t id,
169  BinaryValue value, cMessage* ttlMessage,
170  bool is_modifiable=true,
172  bool responsible=true);
173 
182  virtual void removeData(const OverlayKey& key, uint32_t kind, uint32_t id);
183 
184  void display();
185 
196  uint32_t kind = 0, uint32_t id = 0);
197 
198  protected:
204  void updateDisplayString();
205 
209  void updateTooltip();
210 };
211 
212 #endif