#include <BootstrapOracle.h>
Public Types | |
typedef std::vector< OverlayKey > | KeyList |
holds all OverlayKeys | |
typedef std::map< OverlayKey, DHTEntry > | DataMap |
Public Member Functions | |
void | addPeer (const IPvXAddress &ip, PeerInfo *info) |
Adds new peers to the peer set. | |
void | sendNotificationToAllPeers (int category) |
Sends a NotificationBoard message to all registered peers. | |
virtual void | killPeer (const IPvXAddress &ip) |
Removes a peer from the peerSet. | |
virtual const NodeHandle & | getRandomNode (bool bootstrappedNeeded=true) |
Returns a random NodeHandle. | |
virtual const NodeHandle & | getBootstrapNode () |
Returns a random NodeHandle. | |
virtual void | registerPeer (const TransportAddress &peer) |
Bootstraps peers in the peer set. | |
virtual void | registerPeer (const NodeHandle &peer) |
Bootstraps peers in the peer set. | |
virtual void | removePeer (const TransportAddress &peer) |
Debootstraps peers in the peer set. | |
virtual KeyList * | getKeyList (uint maximumKeys) |
Returns a keylist. | |
virtual DataMap * | getDataMap () |
virtual const OverlayKey & | getRandomKeyListItem () const |
Returns random key from list. | |
virtual void | setOverlayReadyIcon (const TransportAddress &address, bool ready) |
Colors module-icon blue (ready), green (ready, malicious) or red (not ready). | |
virtual PeerInfo * | getPeerInfo (const TransportAddress &peer) |
Searches the peerSet for the specified node. | |
virtual void | setMalicious (const TransportAddress &address, bool malicious) |
Set a node to be malicious. | |
virtual bool | isMalicious (const TransportAddress &address) |
Check if a node is malicious. | |
virtual PeerInfo * | getRandomPeerInfo (uint32_t nodeType=0) |
Selects a random node from the peerSet. | |
virtual PeerInfo * | getPeerInfo (const IPvXAddress &ip) |
Searches the peerSet for the specified node. | |
Protected Types | |
typedef __gnu_cxx::hash_map< IPvXAddress, bootstrapEntry > | PeerHashMap |
Set of nodes participating in the overlay. | |
Protected Member Functions | |
virtual void | initialize () |
Init member function of module. | |
virtual void | handleMessage (cMessage *msg) |
HandleMessage member function of module. | |
virtual void | createKeyList (uint size) |
Member function to create keylist. | |
Protected Attributes | |
KeyList | keyList |
the keylist | |
DataMap | dataMap |
the datamap | |
uint | bootstrappedPeerSize |
number of bootstrapped peers in the peer set | |
uint | bootstrappedMaliciousNodes |
number of bootstrapped malicious nodes in the peer set | |
uint | maliciousNodes |
number of malicious nodes in the peer set | |
double | maliciousNodeRatio |
ratio of current malicious nodes when changing the ratio dynamically | |
cOutVector | maliciousNodesVector |
vector that records the cange of malicious node rate | |
PeerHashMap | peerSet |
Set of nodes participating in the overlay. | |
uint | maxNumberOfKeys |
parameter used by createKeyList() | |
double | keyProbability |
probability of keys to be owned by nodes | |
Private Attributes | |
uint32 | min_ip |
uint32 | max_ip |
used for random node choosing | |
GlobalStatistics * | globalStatistics |
pointer to GlobalStatistics module in this node |
typedef std::vector<OverlayKey> BootstrapOracle::KeyList |
holds all OverlayKeys
typedef std::map<OverlayKey, DHTEntry> BootstrapOracle::DataMap |
typedef __gnu_cxx::hash_map<IPvXAddress, bootstrapEntry> BootstrapOracle::PeerHashMap [protected] |
Set of nodes participating in the overlay.
void BootstrapOracle::addPeer | ( | const IPvXAddress & | ip, | |
PeerInfo * | info | |||
) |
Adds new peers to the peer set.
Called automatically by the underlay, when new peers are created.
ip | IPvXAddress of the peer to add | |
info | underlay specific info of the peer to add |
00183 { 00184 bootstrapEntry temp; 00185 temp.node = new TransportAddress(ip); 00186 temp.info = info; 00187 peerSet.insert(std::make_pair(temp.node->ip, temp)); 00188 // set bounds for random node retrival 00189 if(ip.get4().getInt() < min_ip) min_ip = ip.get4().getInt(); 00190 if(ip.get4().getInt() > max_ip) max_ip = ip.get4().getInt(); 00191 00192 if (uniform(0, 1) < (double) par("maliciousNodeProbability") || 00193 (par("maliciousNodeChange") && uniform(0, 1) < maliciousNodeRatio)) 00194 setMalicious(*temp.node, true); 00195 }
void BootstrapOracle::sendNotificationToAllPeers | ( | int | category | ) |
Sends a NotificationBoard message to all registered peers.
category | Type of notification |
00171 { 00172 PeerHashMap::iterator it; 00173 for (it = peerSet.begin(); it != peerSet.end(); it++) { 00174 NotificationBoard* nb = check_and_cast<NotificationBoard*>( 00175 simulation.module(it->second.info->getModuleID()) 00176 ->submodule("notificationBoard")); 00177 00178 nb->fireChangeNotification(category); 00179 } 00180 }
void BootstrapOracle::killPeer | ( | const IPvXAddress & | ip | ) | [virtual] |
Removes a peer from the peerSet.
Called automatically by the underlay, when peers are removed.
ip | IPvXAddress of the peer to remove |
00261 { 00262 PeerHashMap::iterator it = peerSet.find(ip); 00263 if(it != peerSet.end()) { 00264 if(it->second.info->isBootstrapped()) { 00265 bootstrappedPeerSize--; 00266 if(it->second.info->isMalicious()) 00267 bootstrappedMaliciousNodes--; 00268 it->second.info->setBootstrapped(false); 00269 } 00270 00271 delete it->second.node; 00272 delete it->second.info; 00273 peerSet.erase(it); 00274 } 00275 }
const NodeHandle & BootstrapOracle::getRandomNode | ( | bool | bootstrappedNeeded = true |
) | [virtual] |
Returns a random NodeHandle.
Returns a random NodeHandle from the peerSet if at least one peer has been registered, an empty TransportAddress otherwise.
bootstrappedNeeded | does the node need to be bootstrapped? |
00139 { 00140 if (peerSet.size() == 0) 00141 return NodeHandle::UNSPECIFIED_NODE; 00142 if (bootstrappedNeeded && bootstrappedPeerSize == 0) 00143 return NodeHandle::UNSPECIFIED_NODE; 00144 else { 00145 // return random TransportAddress in O(log n) 00146 PeerHashMap::iterator it = peerSet.end(); 00147 bootstrapEntry tempEntry = {NULL, NULL}; 00148 00149 while(it == peerSet.end() || (bootstrappedNeeded && !it->second.info->isBootstrapped())) { 00150 IPvXAddress randomAddr(intuniform(min_ip, max_ip)); 00151 00152 it = peerSet.find(randomAddr); 00153 00154 if (it == peerSet.end()) { 00155 it = peerSet.insert(std::make_pair(randomAddr,tempEntry)).first; 00156 peerSet.erase(it++); 00157 } 00158 00159 if (it == peerSet.end()) 00160 it = peerSet.begin(); 00161 } 00162 00163 if(dynamic_cast<NodeHandle*>(it->second.node)) 00164 return *dynamic_cast<NodeHandle*>(it->second.node); 00165 else 00166 return NodeHandle::UNSPECIFIED_NODE; 00167 } 00168 }
const NodeHandle & BootstrapOracle::getBootstrapNode | ( | ) | [virtual] |
Returns a random NodeHandle.
Returns a random NodeHandle of an already bootstrapped node from the peerSet if at least one peer has been registered, an empty TransportAddress otherwise.
00134 { 00135 return getRandomNode(true); 00136 }
void BootstrapOracle::registerPeer | ( | const TransportAddress & | peer | ) | [virtual] |
Bootstraps peers in the peer set.
peer | node to register |
00198 { 00199 PeerHashMap::iterator it = peerSet.find(peer.ip); 00200 if (it == peerSet.end()) 00201 error("unable to bootstrap peer, peer is not in peer set"); 00202 else { 00203 PeerInfo* info = it->second.info; 00204 00205 if (!info->isBootstrapped()) { 00206 bootstrappedPeerSize++; 00207 info->setBootstrapped(); 00208 if (info->isMalicious()) 00209 bootstrappedMaliciousNodes++; 00210 } 00211 00212 delete it->second.node; 00213 peerSet.erase(it); 00214 00215 bootstrapEntry temp; 00216 temp.node = new TransportAddress(peer); 00217 temp.info = info; 00218 peerSet.insert(std::make_pair(temp.node->ip, temp)); 00219 } 00220 }
void BootstrapOracle::registerPeer | ( | const NodeHandle & | peer | ) | [virtual] |
Bootstraps peers in the peer set.
peer | node to register |
00223 { 00224 PeerHashMap::iterator it = peerSet.find(peer.ip); 00225 if (it == peerSet.end()) 00226 error("unable to bootstrap peer, peer is not in peer set"); 00227 else { 00228 PeerInfo* info = it->second.info; 00229 00230 if (!info->isBootstrapped()) { 00231 bootstrappedPeerSize++; 00232 info->setBootstrapped(); 00233 if (info->isMalicious()) 00234 bootstrappedMaliciousNodes++; 00235 } 00236 00237 delete it->second.node; 00238 peerSet.erase(it); 00239 00240 bootstrapEntry temp; 00241 temp.node = new NodeHandle(peer); 00242 temp.info = info; 00243 peerSet.insert(std::make_pair(temp.node->ip, temp)); 00244 } 00245 }
void BootstrapOracle::removePeer | ( | const TransportAddress & | peer | ) | [virtual] |
Debootstraps peers in the peer set.
peer | node to remove |
00248 { 00249 PeerHashMap::iterator it = peerSet.find(peer.ip); 00250 if(it != peerSet.end() && it->second.info->isBootstrapped()) { 00251 bootstrappedPeerSize--; 00252 it->second.info->setBootstrapped(false); 00253 00254 if(it->second.info->isMalicious()) 00255 bootstrappedMaliciousNodes--; 00256 it->second.info->setBootstrapped(false); 00257 } 00258 }
BootstrapOracle::KeyList * BootstrapOracle::getKeyList | ( | uint | maximumKeys | ) | [virtual] |
Returns a keylist.
maximumKeys | maximum number of keys in new keylist |
00289 { 00290 if (maximumKeys > keyList.size()) { 00291 maximumKeys = keyList.size(); 00292 } 00293 // copy keylist to temporary keylist 00294 KeyList tmpKeyList; 00295 tmpKeyList.clear(); 00296 for ( uint i=0; i < keyList.size(); i++ ) 00297 tmpKeyList.push_back(keyList[i]); 00298 00299 KeyList* returnList = new KeyList; 00300 00301 for ( uint i=0; i < ((float)maximumKeys * keyProbability); i++) { 00302 uint index = intuniform(0, tmpKeyList.size()-1); 00303 returnList->push_back(tmpKeyList[index]); 00304 tmpKeyList.erase(tmpKeyList.begin()+index); 00305 } 00306 00307 return returnList; 00308 }
BootstrapOracle::DataMap * BootstrapOracle::getDataMap | ( | ) | [virtual] |
const OverlayKey & BootstrapOracle::getRandomKeyListItem | ( | ) | const [virtual] |
void BootstrapOracle::setOverlayReadyIcon | ( | const TransportAddress & | address, | |
bool | ready | |||
) | [virtual] |
Colors module-icon blue (ready), green (ready, malicious) or red (not ready).
address | TransportAddress of the specified node | |
ready | state to visualize |
00388 { 00389 if (ev.isGUI()) { 00390 const char* color; 00391 if (ready) { 00392 // change color if node is malicious 00393 color = isMalicious(address) ? "green" : ""; 00394 } else { 00395 color = "red"; 00396 } 00397 00398 PeerInfo* info = getPeerInfo(address); 00399 if(info != NULL) { 00400 simulation.module(info->getModuleID()) 00401 ->displayString().setTagArg("i2", 1, color); 00402 } 00403 } 00404 }
PeerInfo * BootstrapOracle::getPeerInfo | ( | const TransportAddress & | peer | ) | [virtual] |
Searches the peerSet for the specified node.
peer | TransportAddress of the specified node |
00316 { 00317 PeerHashMap::iterator it = peerSet.find(peer.ip); 00318 if(it == peerSet.end()) 00319 return NULL; 00320 else 00321 return it->second.info; 00322 }
void BootstrapOracle::setMalicious | ( | const TransportAddress & | address, | |
bool | malicious | |||
) | [virtual] |
Set a node to be malicious.
address | TransportAddress of the node | |
malicious | state to set |
00360 { 00361 PeerInfo* peer = getPeerInfo(address); 00362 if(peer != NULL) { 00363 if(malicious && !peer->isMalicious()) { 00364 maliciousNodes++; 00365 if (peer->isBootstrapped()) 00366 bootstrappedMaliciousNodes++; 00367 } 00368 if (!malicious && peer->isMalicious()) { 00369 maliciousNodes--; 00370 if (peer->isBootstrapped()) 00371 bootstrappedMaliciousNodes--; 00372 } 00373 peer->setMalicious(malicious); 00374 } 00375 }
bool BootstrapOracle::isMalicious | ( | const TransportAddress & | address | ) | [virtual] |
Check if a node is malicious.
address | TransportAddress of the node |
00378 { 00379 PeerInfo* peer = getPeerInfo(address); 00380 if(peer != NULL) 00381 return peer->isMalicious(); 00382 00383 return false; 00384 }
PeerInfo * BootstrapOracle::getRandomPeerInfo | ( | uint32_t | nodeType = 0 |
) | [virtual] |
Selects a random node from the peerSet.
nodeType | If != 0, return a node of that type |
00333 { 00334 // return random TransportAddress in O(log n) 00335 PeerHashMap::iterator it; 00336 bootstrapEntry tempEntry = {NULL, NULL}; 00337 00338 IPvXAddress randomAddr(intuniform(min_ip, max_ip)); 00339 00340 it = peerSet.find(randomAddr); 00341 if (it == peerSet.end()) { 00342 it = peerSet.insert(std::make_pair(randomAddr,tempEntry)).first; 00343 peerSet.erase(it++); 00344 } 00345 if (it == peerSet.end()) 00346 it = peerSet.begin(); 00347 00348 // if nodeType != 0, search for next node with the given type 00349 if (nodeType) { 00350 while( it->second.info->getTypeID() != nodeType ) { 00351 ++it; 00352 if (it == peerSet.end()) it = peerSet.begin(); 00353 } 00354 } 00355 00356 return it->second.info; 00357 }
PeerInfo * BootstrapOracle::getPeerInfo | ( | const IPvXAddress & | ip | ) | [virtual] |
Searches the peerSet for the specified node.
ip | IPvXAddress of the specified node |
00325 { 00326 PeerHashMap::iterator it = peerSet.find(ip); 00327 if(it == peerSet.end()) 00328 return NULL; 00329 else 00330 return it->second.info; 00331 }
void BootstrapOracle::initialize | ( | ) | [protected, virtual] |
Init member function of module.
00058 { 00059 maxNumberOfKeys = par("maxNumberOfKeys"); 00060 keyProbability = par("keyProbability"); 00061 WATCH_HASH_MAP(peerSet); 00062 WATCH_MAP(dataMap); 00063 WATCH_VECTOR(keyList); 00064 WATCH(bootstrappedPeerSize); 00065 WATCH(bootstrappedMaliciousNodes); 00066 WATCH(maliciousNodes); 00067 createKeyList(maxNumberOfKeys); 00068 bootstrappedPeerSize = 0; 00069 bootstrappedMaliciousNodes = 0; 00070 maliciousNodes = 0; 00071 00072 if (par("maliciousNodeChange")) { 00073 if ((double) par("maliciousNodeProbability") > 0) 00074 error("maliciousNodeProbability and maliciousNodeChange are not supported concurrently"); 00075 00076 cMessage* msg = new cMessage("maliciousNodeChange"); 00077 scheduleAt(simulation.simTime() + (int) par("maliciousNodeChangeStartTime"), msg); 00078 maliciousNodesVector.setName("MaliciousNodeRate"); 00079 maliciousNodesVector.record(0); 00080 maliciousNodeRatio = 0; 00081 } 00082 00083 min_ip =0xFFFFFFFF; 00084 max_ip =0x00000000; 00085 00086 globalStatistics = GlobalStatisticsAccess().get(); 00087 00088 cMessage* timer = new cMessage("oracleTimer"); 00089 00090 scheduleAt(simulation.simTime(), timer); 00091 }
void BootstrapOracle::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
HandleMessage member function of module.
msg | messag to handle |
00094 { 00095 if (msg->isName("maliciousNodeChange")) { 00096 double newRatio = maliciousNodeRatio + (double) par("maliciousNodeChangeRate"); // ratio to obtain 00097 if (maliciousNodeRatio < (double) par("maliciousNodeChangeStartValue")) 00098 newRatio = (double) par("maliciousNodeChangeStartValue"); 00099 00100 if (newRatio < (double) par("maliciousNodeChangeStopValue")) // schedule next event 00101 scheduleAt(simulation.simTime() + (int) par("maliciousNodeChangeInterval"), msg); 00102 00103 int nodesNeeded = (int) (((double) par("maliciousNodeChangeRate")) * peerSet.size()); 00104 00105 EV << "[BootstrapOracle::handleMessage()]\n" 00106 << " Changing " << nodesNeeded << " nodes to be malicious" 00107 << endl; 00108 00109 for (int i = 0; i < nodesNeeded; i++) { 00110 // search a node that is not yet malicious 00111 NodeHandle node; 00112 do node = getRandomNode(false); 00113 while (isMalicious(node)); 00114 00115 setMalicious(node, true); 00116 } 00117 00118 maliciousNodesVector.record(newRatio); 00119 maliciousNodeRatio = newRatio; 00120 00121 return; 00122 } 00123 00124 else if (msg->isName("oracleTimer")) { 00125 RECORD_STATS(globalStatistics->recordOutVector( 00126 "BootstrapOracle: Number of nodes", peerSet.size())); 00127 scheduleAt(simulation.simTime() + 10, msg); 00128 } else { 00129 opp_error("BootstrapOracle::handleMessage: Unknown message type!"); 00130 } 00131 }
void BootstrapOracle::createKeyList | ( | uint | size | ) | [protected, virtual] |
Member function to create keylist.
size | size of new keylist |
00278 { 00279 for(uint i = 0; i < size; i++) 00280 keyList.push_back(OverlayKey::random()); 00281 }
KeyList BootstrapOracle::keyList [protected] |
the keylist
DataMap BootstrapOracle::dataMap [protected] |
the datamap
uint BootstrapOracle::bootstrappedPeerSize [protected] |
number of bootstrapped peers in the peer set
uint BootstrapOracle::bootstrappedMaliciousNodes [protected] |
number of bootstrapped malicious nodes in the peer set
uint BootstrapOracle::maliciousNodes [protected] |
number of malicious nodes in the peer set
double BootstrapOracle::maliciousNodeRatio [protected] |
ratio of current malicious nodes when changing the ratio dynamically
cOutVector BootstrapOracle::maliciousNodesVector [protected] |
vector that records the cange of malicious node rate
PeerHashMap BootstrapOracle::peerSet [protected] |
Set of nodes participating in the overlay.
uint BootstrapOracle::maxNumberOfKeys [protected] |
parameter used by createKeyList()
double BootstrapOracle::keyProbability [protected] |
probability of keys to be owned by nodes
uint32 BootstrapOracle::min_ip [private] |
uint32 BootstrapOracle::max_ip [private] |
used for random node choosing
pointer to GlobalStatistics module in this node