#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.
00063 { 00064 return dataMap.size(); 00065 }
void DHTDataStorage::clear | ( | ) | [virtual] |
bool DHTDataStorage::isEmpty | ( | ) | [virtual] |
Checks if the data storage map is empty.
00068 { 00069 if (dataMap.size() == 0) 00070 return true; 00071 else 00072 return false; 00073 }
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 |
00075 { 00076 00077 std::map<OverlayKey, DHTData>::iterator it = dataMap.find(key); 00078 00079 if (it == dataMap.end()) 00080 return BinaryValue::UNSPECIFIED_VALUE; 00081 else 00082 return it->second.value; 00083 }
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 |
00085 { 00086 00087 std::map<OverlayKey, DHTData>::iterator it = dataMap.find(key); 00088 00089 if (it == dataMap.end()) 00090 return NodeHandle::UNSPECIFIED_NODE; 00091 else 00092 return it->second.sourceNode; 00093 }
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 |
00095 { 00096 std::map<OverlayKey, DHTData>::iterator it = dataMap.find(key); 00097 00098 if (it == dataMap.end()) 00099 return NULL; 00100 else 00101 return it->second.ttlMessage; 00102 }
const bool DHTDataStorage::isModifiable | ( | const OverlayKey & | key | ) | [virtual] |
Returns a boolean telling if this data if modifiable.
key | The key of the data item |
00104 { 00105 00106 std::map<OverlayKey, DHTData>::iterator it = dataMap.find(key); 00107 00108 if (it == dataMap.end()) 00109 return true; 00110 else 00111 return it->second.is_modifiable; 00112 }
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 |
00116 { 00117 if (pos >= dataMap.size()) { 00118 error("Index out of bound (DHTDataStorage, getDataAtPos())"); 00119 } 00120 00121 std::map<OverlayKey, DHTData>::iterator it = dataMap.begin(); 00122 for (uint i= 0; i < pos; i++) { 00123 it++; 00124 if (i == (pos-1)) 00125 return it->second.value; 00126 } 00127 return it->second.value; 00128 }
const std::map< OverlayKey, DHTData >::iterator DHTDataStorage::begin | ( | ) | [virtual] |
Returns an iterator to the beginning of the map.
00131 { 00132 return dataMap.begin(); 00133 }
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 | |
responsible |
00136 { 00137 DHTData entry; 00138 entry.value = value; 00139 entry.ttlMessage = ttlMessage; 00140 entry.sourceNode = sourceNode; 00141 entry.is_modifiable = is_modifiable; 00142 entry.responsible = responsible; 00143 // replace with new value 00144 dataMap.erase(key); 00145 dataMap.insert(make_pair(key, entry)); 00146 }
void DHTDataStorage::removeData | ( | OverlayKey | key | ) | [virtual] |
Removes a certain data item from the map.
key | The key of the data item to be removed |
00149 { 00150 dataMap.erase(key); 00151 }
void DHTDataStorage::display | ( | ) |
00214 { 00215 cout << "Content of DHTDataStorage:" << endl; 00216 for (std::map<OverlayKey, DHTData>::iterator it = dataMap.begin(); 00217 it != dataMap.end(); it++) { 00218 cout << "Key: " << it->first << " Value: " << it->second.value << "End-time: " << it->second.ttlMessage->arrivalTime() << endl; 00219 } 00220 }
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 |
00154 { 00155 dhtDataVector* vect = new dhtDataVector(); 00156 map<OverlayKey, DHTData>::iterator iter; 00157 if (lkey > rkey) { //the zero key is between this to keys 00158 //we fetch everything after lkey 00159 for( iter = dataMap.lower_bound(lkey); iter != dataMap.end(); iter++ ) { 00160 vect->insert(vect->end(), std::make_pair(iter->first, iter->second)); 00161 } 00162 //and everything before rkey 00163 for( iter = dataMap.upper_bound(rkey); iter != (dataMap.begin()--); iter-- ) { 00164 vect->insert(vect->end(), std::make_pair(iter->first, iter->second)); 00165 } 00166 } 00167 else { 00168 for (iter = dataMap.lower_bound(lkey); iter != (dataMap.upper_bound(rkey) ++); iter++) { 00169 vect->insert(vect->end(), std::make_pair(iter->first, iter->second)); 00170 } 00171 } 00172 00173 return vect; 00174 }
void DHTDataStorage::updateDisplayString | ( | ) | [protected] |
Displays the current number of successors in the list.
00177 { 00178 // FIXME: doesn't work without tcl/tk 00179 // if (ev.isGUI()) { 00180 if (1) { 00181 char buf[80]; 00182 00183 if (dataMap.size() == 1) { 00184 sprintf(buf, "1 data item"); 00185 } else { 00186 sprintf(buf, "%zi data items", dataMap.size()); 00187 } 00188 00189 displayString().setTagArg("t", 0, buf); 00190 displayString().setTagArg("t", 2, "blue"); 00191 } 00192 00193 }
void DHTDataStorage::updateTooltip | ( | ) | [protected] |
Displays the first 4 successor nodes as tooltip.
00196 { 00197 if (ev.isGUI()) { 00198 std::stringstream str; 00199 for (uint i = 0; i < dataMap.size(); i++) { 00200 str << getDataAtPos(i); 00201 00202 if ( i != dataMap.size() - 1 ) 00203 str << endl; 00204 } 00205 00206 00207 char buf[1024]; 00208 sprintf(buf, "%s", str.str().c_str()); 00209 displayString().setTagArg("tt", 0, buf); 00210 } 00211 }
std::map<OverlayKey, DHTData> DHTDataStorage::dataMap [protected] |
internal representation of the data storage