35 os <<
"Value: " << entry.
value
36 <<
" Kind: " << entry.
kind
37 <<
" ID: " << entry.
id
38 <<
" Endtime: " << entry.
ttlMessage->getArrivalTime()
43 os <<
" siblingVote:";
45 for (SiblingVoteMap::const_iterator it = entry.
siblingVote.begin();
47 os <<
" " << it->first <<
" (" << it->second.size() <<
")";
64 error(
"This module doesn't handle messages!");
69 map<OverlayKey, DhtDataEntry>::iterator iter;
71 for( iter = dataMap.begin(); iter != dataMap.end(); iter++ ) {
72 cancelAndDelete(iter->second.ttlMessage);
81 return dataMap.size();
85 uint32_t kind, uint32_t
id)
87 pair<DhtDataMap::iterator, DhtDataMap::iterator> pos =
88 dataMap.equal_range(key);
90 while (pos.first != pos.second) {
91 if ((pos.first->second.kind == kind) &&
92 (pos.first->second.id ==
id)) {
93 return &pos.first->second;
104 uint32_t kind, uint32_t
id)
109 pair<DhtDataMap::iterator, DhtDataMap::iterator> pos =
110 dataMap.equal_range(key);
112 while (pos.first != pos.second) {
113 entry = pos.first->second;
114 vect->push_back(make_pair(key, entry));
123 uint32_t kind, uint32_t
id)
134 uint32_t kind, uint32_t
id)
147 return dataMap.begin();
152 return dataMap.end();
170 if ((kind == 0) || (
id == 0)) {
171 throw cRuntimeError(
"DHTDataStorage::addData(): "
172 "Not allowed to add data with kind = 0 or id = 0!");
175 pair<DhtDataMap::iterator, DhtDataMap::iterator> pos =
176 dataMap.equal_range(key);
179 while ((pos.first != pos.second) && (pos.first->second.kind < kind)) {
183 while ((pos.first != pos.second) && (pos.first->second.kind == kind)
184 && (pos.first->second.id <
id)) {
188 return &(dataMap.insert(pos.first, make_pair(key, entry))->second);
194 pair<DhtDataMap::iterator, DhtDataMap::iterator> pos =
195 dataMap.equal_range(key);
197 while (pos.first != pos.second) {
199 if (((kind == 0) || (pos.first->second.kind == kind)) &&
200 ((
id == 0) || (pos.first->second.id ==
id))) {
201 cancelAndDelete(pos.first->second.ttlMessage);
202 dataMap.erase(pos.first++);
215 DhtDataMap::iterator iter, end;
218 iter = dataMap.begin();
221 iter = dataMap.lower_bound(key);
222 end = dataMap.upper_bound(key);
225 for (; iter != end; iter++) {
226 if (((kind == 0) || (iter->second.kind == kind)) &&
227 ((
id == 0) || (iter->second.id ==
id))) {
229 entry.
setKey(iter->first);
230 entry.
setKind(iter->second.kind);
231 entry.
setId(iter->second.id);
233 entry.
setTtl((
int)SIMTIME_DBL(
234 iter->second.ttlMessage->getArrivalTime() - simTime()));
238 vect->push_back(entry);
252 if (dataMap.size() == 1) {
253 sprintf(buf,
"1 data item");
255 sprintf(buf,
"%zi data items", dataMap.size());
258 getDisplayString().setTagArg(
"t", 0, buf);
259 getDisplayString().setTagArg(
"t", 2,
"blue");
268 std::stringstream str;
270 for (DhtDataMap::iterator it = dataMap.begin();
271 it != dataMap.end(); it++) {
272 str << it->second.value;
278 sprintf(buf,
"%s", str.str().c_str());
279 getDisplayString().setTagArg(
"tt", 0, buf);
286 cout <<
"Content of DHTDataStorage:" << endl;
287 for (DhtDataMap::iterator it = dataMap.begin();
288 it != dataMap.end(); it++) {
289 cout <<
"Key: " << it->first <<
" Kind: " << it->second.kind
290 <<
" ID: " << it->second.id <<
" Value: "
291 << it->second.value <<
"End-time: "
292 << it->second.ttlMessage->getArrivalTime() << endl;