#include <DHTDataStorage.h>
Public Member Functions | |
virtual int | numInitStages () const |
virtual void | initialize (int stage) |
virtual void | handleMessage (cMessage *msg) |
virtual uint | getSize () |
Returns number of stored data items in the map. | |
virtual void | clear () |
Clears all stored data items. | |
virtual bool | isEmpty () |
Checks if the data storage map is empty. | |
virtual const BinaryValue & | getData (const OverlayKey &key) |
Returns the value of a stored data item with a given key. | |
virtual const NodeHandle & | getSourceNode (const OverlayKey &key) |
Returns the source node of a stored data item with a given key. | |
virtual cMessage * | getTtlMessage (const OverlayKey &key) |
Returns the ttlMessage of a stored data item with a given key. | |
virtual const bool | isModifiable (const OverlayKey &key) |
Returns a boolean telling if this data if modifiable. | |
virtual const BinaryValue & | getDataAtPos (uint pos=0) |
Returns the value of the data item stored at position pos. | |
virtual const std::map< OverlayKey, DHTData >::iterator | begin () |
Returns an iterator to the beginning of the map. | |
virtual void | addData (OverlayKey key, BinaryValue value, cMessage *ttlMessage, bool is_modifiable=true, NodeHandle sourceNode=NodeHandle::UNSPECIFIED_NODE, bool responsible=true) |
Store a new data item in the map. | |
virtual void | removeData (OverlayKey key) |
Removes a certain data item from the map. | |
void | display () |
dhtDataVector * | get_range (const OverlayKey lkey, const OverlayKey rkey) |
Return a vector containing every keys/values between the two bounds. | |
Protected Member Functions | |
void | updateDisplayString () |
Displays the current number of successors in the list. | |
void | updateTooltip () |
Displays the first 4 successor nodes as tooltip. | |
Protected Attributes | |
std::map< OverlayKey, DHTData > | dataMap |
internal representation of the data storage |
virtual int DHTDataStorage::numInitStages | ( | ) | const [inline, virtual] |
void DHTDataStorage::initialize | ( | int | stage | ) | [virtual] |
void DHTDataStorage::handleMessage | ( | cMessage * | msg | ) | [virtual] |
uint DHTDataStorage::getSize | ( | ) | [virtual] |
Returns number of stored data items in the map.
00059 { 00060 return dataMap.size(); 00061 }
void DHTDataStorage::clear | ( | ) | [virtual] |
bool DHTDataStorage::isEmpty | ( | ) | [virtual] |
Checks if the data storage map is empty.
00064 { 00065 if (dataMap.size() == 0) 00066 return true; 00067 else 00068 return false; 00069 }
const BinaryValue & DHTDataStorage::getData | ( | const OverlayKey & | key | ) | [virtual] |
Returns the value of a stored data item with a given key.
key | The key of the data item |
00071 { 00072 00073 std::map<OverlayKey, DHTData>::iterator it = dataMap.find(key); 00074 00075 if (it == dataMap.end()) 00076 return BinaryValue::UNSPECIFIED_VALUE; 00077 else 00078 return it->second.value; 00079 }
const NodeHandle & DHTDataStorage::getSourceNode | ( | const OverlayKey & | key | ) | [virtual] |
Returns the source node of a stored data item with a given key.
key | The key of the data item |
00081 { 00082 00083 std::map<OverlayKey, DHTData>::iterator it = dataMap.find(key); 00084 00085 if (it == dataMap.end()) 00086 return NodeHandle::UNSPECIFIED_NODE; 00087 else 00088 return it->second.sourceNode; 00089 }
cMessage * DHTDataStorage::getTtlMessage | ( | const OverlayKey & | key | ) | [virtual] |
Returns the ttlMessage of a stored data item with a given key.
key | The key of the data item |
00091 { 00092 std::map<OverlayKey, DHTData>::iterator it = dataMap.find(key); 00093 00094 if (it == dataMap.end()) 00095 return NULL; 00096 else 00097 return it->second.ttlMessage; 00098 }
const bool DHTDataStorage::isModifiable | ( | const OverlayKey & | key | ) | [virtual] |
Returns a boolean telling if this data if modifiable.
key | The key of the data item |
00100 { 00101 00102 std::map<OverlayKey, DHTData>::iterator it = dataMap.find(key); 00103 00104 if (it == dataMap.end()) 00105 return true; 00106 else 00107 return it->second.is_modifiable; 00108 }
const BinaryValue & DHTDataStorage::getDataAtPos | ( | uint | pos = 0 |
) | [virtual] |
Returns the value of the data item stored at position pos.
pos | position in data storage map |
00112 { 00113 if (pos >= dataMap.size()) { 00114 error("Index out of bound (DHTDataStorage, getDataAtPos())"); 00115 } 00116 00117 std::map<OverlayKey, DHTData>::iterator it = dataMap.begin(); 00118 for (uint i= 0; i < pos; i++) { 00119 it++; 00120 if (i == (pos-1)) 00121 return it->second.value; 00122 } 00123 return it->second.value; 00124 }
const std::map< OverlayKey, DHTData >::iterator DHTDataStorage::begin | ( | ) | [virtual] |
Returns an iterator to the beginning of the map.
00127 { 00128 return dataMap.begin(); 00129 }
void DHTDataStorage::addData | ( | OverlayKey | key, | |
BinaryValue | value, | |||
cMessage * | ttlMessage, | |||
bool | is_modifiable = true , |
|||
NodeHandle | sourceNode = NodeHandle::UNSPECIFIED_NODE , |
|||
bool | responsible = true | |||
) | [virtual] |
Store a new data item in the map.
key | The key of the data item to be stored | |
value | The value of the data item to be stored | |
ttlMessage | The self-message sent for the ttl expiration | |
is_modifiable | Flag that tell if the data can be change by anyone, or just by the sourceNode | |
sourceNode | Node which asked to store the value |
00132 { 00133 DHTData entry; 00134 entry.value = value; 00135 entry.ttlMessage = ttlMessage; 00136 entry.sourceNode = sourceNode; 00137 entry.is_modifiable = is_modifiable; 00138 entry.responsible = responsible; 00139 // replace with new value 00140 dataMap.erase(key); 00141 dataMap.insert(make_pair(key, entry)); 00142 }
void DHTDataStorage::removeData | ( | OverlayKey | key | ) | [virtual] |
void DHTDataStorage::display | ( | ) |
00210 { 00211 cout << "Content of DHTDataStorage:" << endl; 00212 for (std::map<OverlayKey, DHTData>::iterator it = dataMap.begin(); 00213 it != dataMap.end(); it++) { 00214 cout << "Key: " << it->first << " Value: " << it->second.value << "End-time: " << it->second.ttlMessage->arrivalTime() << endl; 00215 } 00216 }
dhtDataVector * DHTDataStorage::get_range | ( | const OverlayKey | lkey, | |
const OverlayKey | rkey | |||
) |
Return a vector containing every keys/values between the two bounds.
lkey | The beginning of the range | |
rkey | The end of the range |
00150 { 00151 dhtDataVector* vect = new dhtDataVector(); 00152 map<OverlayKey, DHTData>::iterator iter; 00153 if (lkey > rkey) { //the zero key is between this to keys 00154 //we fetch everything after lkey 00155 for( iter = dataMap.lower_bound(lkey); iter != dataMap.end(); iter++ ) { 00156 vect->insert(vect->end(), std::make_pair(iter->first, iter->second)); 00157 } 00158 //and everything before rkey 00159 for( iter = dataMap.upper_bound(rkey); iter != (dataMap.begin()--); iter-- ) { 00160 vect->insert(vect->end(), std::make_pair(iter->first, iter->second)); 00161 } 00162 } 00163 else { 00164 for (iter = dataMap.lower_bound(lkey); iter != (dataMap.upper_bound(rkey) ++); iter++) { 00165 vect->insert(vect->end(), std::make_pair(iter->first, iter->second)); 00166 } 00167 } 00168 00169 return vect; 00170 }
void DHTDataStorage::updateDisplayString | ( | ) | [protected] |
Displays the current number of successors in the list.
00173 { 00174 // FIXME: doesn't work without tcl/tk 00175 // if (ev.isGUI()) { 00176 if (1) { 00177 char buf[80]; 00178 00179 if (dataMap.size() == 1) { 00180 sprintf(buf, "1 data item"); 00181 } else { 00182 sprintf(buf, "%zi data items", dataMap.size()); 00183 } 00184 00185 displayString().setTagArg("t", 0, buf); 00186 displayString().setTagArg("t", 2, "blue"); 00187 } 00188 00189 }
void DHTDataStorage::updateTooltip | ( | ) | [protected] |
Displays the first 4 successor nodes as tooltip.
00192 { 00193 if (ev.isGUI()) { 00194 std::stringstream str; 00195 for (uint i = 0; i < dataMap.size(); i++) { 00196 str << getDataAtPos(i); 00197 00198 if ( i != dataMap.size() - 1 ) 00199 str << endl; 00200 } 00201 00202 00203 char buf[1024]; 00204 sprintf(buf, "%s", str.str().c_str()); 00205 displayString().setTagArg("tt", 0, buf); 00206 } 00207 }
std::map<OverlayKey, DHTData> DHTDataStorage::dataMap [protected] |
internal representation of the data storage