#include <BootstrapOracle.h>
Public Types | |
typedef std::vector< OverlayKey > | KeyList |
holds all OverlayKeys | |
Public Member Functions | |
~BootstrapOracle () | |
Destructor. | |
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 (uint32_t nodeType=0, bool bootstrappedNeeded=true) |
Returns a random NodeHandle. | |
virtual const NodeHandle & | getBootstrapNode (const NodeHandle &node=NodeHandle::UNSPECIFIED_NODE) |
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 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. | |
void | setPreKilled (const TransportAddress &address) |
Mark a node for deletion. | |
TransportAddress * | getRandomAliveNode (uint32_t nodeType=0) |
Selects a random node from the peerSet, which is not already marked for deletion. | |
virtual PeerInfo * | getRandomPeerInfo (uint32_t nodeType=0, bool bootstrapNeeded=false) |
Selects a random node from the peerSet. | |
virtual PeerInfo * | getPeerInfo (const IPvXAddress &ip) |
Searches the peerSet for the specified node. | |
bool | areNodeTypesConnected (uint32_t a, uint32_t b) |
void | connectNodeTypes (uint32_t a, uint32_t b) |
void | disconnectNodeTypes (uint32_t a, uint32_t b) |
void | mergeBootstrapNodes (int toPartition, int fromPartition, int numNodes) |
Protected Types | |
typedef UNORDERED_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 | |
uint | bootstrappedPeerSize |
number of bootstrapped peers in the peer set | |
uint | bootstrappedPeerSizePerType [MAX_NODETYPES] |
number of bootstrapped peers of all types | |
uint | bootstrappedMaliciousNodes |
number of bootstrapped malicious nodes in the peer set | |
uint | maliciousNodes |
number of malicious nodes in the peer set | |
uint | preKilledNodes |
number of nodes marked for deletion 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 | |
bool | connectionMatrix [MAX_NODETYPES][MAX_NODETYPES] |
matrix specifices with node types (partitions) can communication |
typedef std::vector<OverlayKey> BootstrapOracle::KeyList |
holds all OverlayKeys
typedef UNORDERED_MAP<IPvXAddress, bootstrapEntry> BootstrapOracle::PeerHashMap [protected] |
Set of nodes participating in the overlay.
BootstrapOracle::~BootstrapOracle | ( | ) |
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 |
Referenced by SimpleNetConfigurator::createNode(), IPv4UnderlayConfigurator::createNode(), SingleHostConfigurator::initializeUnderlay(), IPv4UnderlayConfigurator::initializeUnderlay(), SimpleNetConfigurator::migrateNode(), and IPv4UnderlayConfigurator::migrateNode().
00234 { 00235 bootstrapEntry temp; 00236 temp.node = new TransportAddress(ip); 00237 temp.info = info; 00238 temp.info->setPreKilled(false); 00239 00240 peerSet.insert(std::make_pair(temp.node->ip, temp)); 00241 // set bounds for random node retrieval 00242 if (ip.get4().getInt() < min_ip) min_ip = ip.get4().getInt(); 00243 if (ip.get4().getInt() > max_ip) max_ip = ip.get4().getInt(); 00244 00245 if (uniform(0, 1) < (double) par("maliciousNodeProbability") || 00246 (par("maliciousNodeChange") && uniform(0, 1) < maliciousNodeRatio)) { 00247 setMalicious(*temp.node, true); 00248 } 00249 }
void BootstrapOracle::sendNotificationToAllPeers | ( | int | category | ) |
Sends a NotificationBoard message to all registered peers.
category | Type of notification |
00222 { 00223 PeerHashMap::iterator it; 00224 for (it = peerSet.begin(); it != peerSet.end(); it++) { 00225 NotificationBoard* nb = check_and_cast<NotificationBoard*>( 00226 simulation.module(it->second.info->getModuleID()) 00227 ->submodule("notificationBoard")); 00228 00229 nb->fireChangeNotification(category); 00230 } 00231 }
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 |
Referenced by SimpleNetConfigurator::handleTimerEvent(), IPv4UnderlayConfigurator::handleTimerEvent(), SimpleNetConfigurator::migrateNode(), and IPv4UnderlayConfigurator::migrateNode().
00321 { 00322 PeerHashMap::iterator it = peerSet.find(ip); 00323 if(it != peerSet.end()) { 00324 if(it->second.info->isBootstrapped()) { 00325 bootstrappedPeerSize--; 00326 bootstrappedPeerSizePerType[it->second.info->getTypeID()]--; 00327 00328 if(it->second.info->isMalicious()) 00329 bootstrappedMaliciousNodes--; 00330 00331 it->second.info->setBootstrapped(false); 00332 } 00333 00334 if (it->second.info->isPreKilled()) { 00335 it->second.info->setPreKilled(false); 00336 preKilledNodes--; 00337 } 00338 00339 delete it->second.node; 00340 delete it->second.info; 00341 peerSet.erase(it); 00342 } 00343 }
const NodeHandle & BootstrapOracle::getRandomNode | ( | uint32_t | nodeType = 0 , |
|
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.
nodeType | If != 0, return a node of that type | |
bootstrappedNeeded | does the node need to be bootstrapped? |
Referenced by getBootstrapNode(), handleMessage(), and mergeBootstrapNodes().
00186 { 00187 if (peerSet.size() == 0) 00188 return NodeHandle::UNSPECIFIED_NODE; 00189 if (bootstrappedNeeded && bootstrappedPeerSize == 0) 00190 return NodeHandle::UNSPECIFIED_NODE; 00191 if (nodeType && bootstrappedPeerSizePerType[nodeType] == 0) 00192 return NodeHandle::UNSPECIFIED_NODE; 00193 else { 00194 // return random TransportAddress in O(log n) 00195 PeerHashMap::iterator it = peerSet.end(); 00196 bootstrapEntry tempEntry = {NULL, NULL}; 00197 00198 while(it == peerSet.end() ||(nodeType && (it->second.info->getTypeID() != nodeType)) 00199 || (bootstrappedNeeded && !it->second.info->isBootstrapped())) { 00200 IPvXAddress randomAddr(intuniform(min_ip, max_ip)); 00201 00202 it = peerSet.find(randomAddr); 00203 00204 if (it == peerSet.end()) { 00205 it = peerSet.insert(std::make_pair(randomAddr,tempEntry)).first; 00206 peerSet.erase(it++); 00207 } 00208 00209 if (it == peerSet.end()) 00210 it = peerSet.begin(); 00211 } 00212 00213 if (dynamic_cast<NodeHandle*>(it->second.node)) { 00214 return *dynamic_cast<NodeHandle*>(it->second.node); 00215 } else { 00216 return NodeHandle::UNSPECIFIED_NODE; 00217 } 00218 } 00219 }
const NodeHandle & BootstrapOracle::getBootstrapNode | ( | const NodeHandle & | node = NodeHandle::UNSPECIFIED_NODE |
) | [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. If the optional node parameter is given, try to return a bootstrap node in the same partition.
node | Find a bootstrap node in the same partitions as node |
Referenced by BootstrapList::getBootstrapNode(), KBRTestApp::handleTimerEvent(), and PubSubMMOG::initializeOverlay().
00147 { 00148 uint32_t nodeType; 00149 PeerHashMap::iterator it; 00150 00151 // always prefer boot node from the same partition 00152 // if there is no such node, go through all 00153 // connected partitions until a bootstrap node is found 00154 if (!node.isUnspecified()) { 00155 it = peerSet.find(node.getAddress()); 00156 00157 // this should never happen 00158 if (it == peerSet.end()) { 00159 return getRandomNode(0, true); 00160 } 00161 00162 nodeType = it->second.info->getTypeID(); 00163 const NodeHandle &tempNode1 = getRandomNode(nodeType, true); 00164 00165 if (tempNode1.isUnspecified()) { 00166 for (uint i = 1; i < MAX_NODETYPES; i++) { 00167 if (i == nodeType) 00168 continue; 00169 00170 if (connectionMatrix[nodeType][i]) { 00171 const NodeHandle &tempNode2 = getRandomNode(i, true); 00172 if (!tempNode2.isUnspecified()) 00173 return tempNode2; 00174 } 00175 } 00176 return NodeHandle::UNSPECIFIED_NODE; 00177 } else { 00178 return tempNode1; 00179 } 00180 } else { 00181 return getRandomNode(0, true); 00182 } 00183 }
void BootstrapOracle::registerPeer | ( | const TransportAddress & | peer | ) | [virtual] |
Bootstraps peers in the peer set.
peer | node to register |
Referenced by Vast::changeState(), SingleHostConfigurator::initializeUnderlay(), and BootstrapList::registerBootstrapNode().
00252 { 00253 PeerHashMap::iterator it = peerSet.find(peer.ip); 00254 if (it == peerSet.end()) 00255 error("unable to bootstrap peer, peer is not in peer set"); 00256 else { 00257 PeerInfo* info = it->second.info; 00258 00259 if (!info->isBootstrapped()) { 00260 bootstrappedPeerSize++; 00261 bootstrappedPeerSizePerType[info->getTypeID()]++; 00262 info->setBootstrapped(); 00263 00264 if (info->isMalicious()) 00265 bootstrappedMaliciousNodes++; 00266 } 00267 00268 delete it->second.node; 00269 peerSet.erase(it); 00270 00271 bootstrapEntry temp; 00272 temp.node = new TransportAddress(peer); 00273 temp.info = info; 00274 peerSet.insert(std::make_pair(temp.node->ip, temp)); 00275 } 00276 }
void BootstrapOracle::registerPeer | ( | const NodeHandle & | peer | ) | [virtual] |
Bootstraps peers in the peer set.
peer | node to register |
00279 { 00280 PeerHashMap::iterator it = peerSet.find(peer.ip); 00281 if (it == peerSet.end()) 00282 error("unable to bootstrap peer, peer is not in peer set"); 00283 else { 00284 PeerInfo* info = it->second.info; 00285 00286 if (!info->isBootstrapped()) { 00287 bootstrappedPeerSize++; 00288 bootstrappedPeerSizePerType[info->getTypeID()]++; 00289 info->setBootstrapped(); 00290 00291 if (info->isMalicious()) 00292 bootstrappedMaliciousNodes++; 00293 } 00294 00295 delete it->second.node; 00296 peerSet.erase(it); 00297 00298 bootstrapEntry temp; 00299 temp.node = new NodeHandle(peer); 00300 temp.info = info; 00301 peerSet.insert(std::make_pair(temp.node->ip, temp)); 00302 } 00303 }
void BootstrapOracle::removePeer | ( | const TransportAddress & | peer | ) | [virtual] |
Debootstraps peers in the peer set.
peer | node to remove |
Referenced by Vast::changeState(), Vast::finishOverlay(), SimpleNetConfigurator::preKillNode(), IPv4UnderlayConfigurator::preKillNode(), and BootstrapList::removeBootstrapNode().
00306 { 00307 PeerHashMap::iterator it = peerSet.find(peer.ip); 00308 if(it != peerSet.end() && it->second.info->isBootstrapped()) { 00309 bootstrappedPeerSize--; 00310 bootstrappedPeerSizePerType[it->second.info->getTypeID()]--; 00311 it->second.info->setBootstrapped(false); 00312 00313 if(it->second.info->isMalicious()) 00314 bootstrappedMaliciousNodes--; 00315 00316 it->second.info->setBootstrapped(false); 00317 } 00318 }
BootstrapOracle::KeyList * BootstrapOracle::getKeyList | ( | uint | maximumKeys | ) | [virtual] |
Returns a keylist.
maximumKeys | maximum number of keys in new keylist |
Referenced by GIASearchApp::handleTimerEvent().
00352 { 00353 if (maximumKeys > keyList.size()) { 00354 maximumKeys = keyList.size(); 00355 } 00356 // copy keylist to temporary keylist 00357 KeyList tmpKeyList; 00358 tmpKeyList.clear(); 00359 00360 for (uint i=0; i < keyList.size(); i++) { 00361 tmpKeyList.push_back(keyList[i]); 00362 } 00363 00364 KeyList* returnList = new KeyList; 00365 00366 for (uint i=0; i < ((float)maximumKeys * keyProbability); i++) { 00367 uint index = intuniform(0, tmpKeyList.size()-1); 00368 00369 returnList->push_back(tmpKeyList[index]); 00370 tmpKeyList.erase(tmpKeyList.begin()+index); 00371 } 00372 00373 return returnList; 00374 }
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 |
Referenced by BaseOverlay::setOverlayReady().
00511 { 00512 if (ev.isGUI()) { 00513 const char* color; 00514 00515 if (ready) { 00516 // change color if node is malicious 00517 color = isMalicious(address) ? "green" : ""; 00518 } else { 00519 color = "red"; 00520 } 00521 00522 PeerInfo* info = getPeerInfo(address); 00523 00524 if(info != NULL) { 00525 simulation.module(info->getModuleID()) 00526 ->displayString().setTagArg("i2", 1, color); 00527 } 00528 } 00529 }
PeerInfo * BootstrapOracle::getPeerInfo | ( | const TransportAddress & | peer | ) | [virtual] |
Searches the peerSet for the specified node.
peer | TransportAddress of the specified node |
Referenced by TopologyVis::deleteOverlayNeighborArrow(), SimpleNetConfigurator::handleTimerEvent(), IPv4UnderlayConfigurator::handleTimerEvent(), isMalicious(), SimpleNetConfigurator::migrateNode(), IPv4UnderlayConfigurator::migrateNode(), SimpleNetConfigurator::preKillNode(), IPv4UnderlayConfigurator::preKillNode(), SimpleUDP::processMsgFromApp(), setMalicious(), setOverlayReadyIcon(), setPreKilled(), and TopologyVis::showOverlayNeighborArrow().
00382 { 00383 PeerHashMap::iterator it = peerSet.find(peer.ip); 00384 00385 if (it == peerSet.end()) 00386 return NULL; 00387 else 00388 return it->second.info; 00389 }
void BootstrapOracle::setMalicious | ( | const TransportAddress & | address, | |
bool | malicious | |||
) | [virtual] |
Set a node to be malicious.
address | TransportAddress of the node | |
malicious | state to set |
Referenced by addPeer(), and handleMessage().
00478 { 00479 PeerInfo* peer = getPeerInfo(address); 00480 00481 if (peer != NULL) { 00482 if(malicious && !peer->isMalicious()) { 00483 maliciousNodes++; 00484 if (peer->isBootstrapped()) { 00485 bootstrappedMaliciousNodes++; 00486 } 00487 } 00488 00489 if (!malicious && peer->isMalicious()) { 00490 maliciousNodes--; 00491 if (peer->isBootstrapped()) { 00492 bootstrappedMaliciousNodes--; 00493 } 00494 } 00495 peer->setMalicious(malicious); 00496 } 00497 }
bool BootstrapOracle::isMalicious | ( | const TransportAddress & | address | ) | [virtual] |
Check if a node is malicious.
address | TransportAddress of the node |
Referenced by handleMessage(), BaseOverlay::isMalicious(), and setOverlayReadyIcon().
00500 { 00501 PeerInfo* peer = getPeerInfo(address); 00502 00503 if(peer != NULL) 00504 return peer->isMalicious(); 00505 00506 return false; 00507 }
void BootstrapOracle::setPreKilled | ( | const TransportAddress & | address | ) |
Mark a node for deletion.
address | TransportAddress of the node |
Referenced by SimpleNetConfigurator::preKillNode().
00431 { 00432 PeerInfo* peer = getPeerInfo(address); 00433 00434 if ((peer != NULL) && !(peer->isPreKilled())) { 00435 preKilledNodes++; 00436 peer->setPreKilled(true); 00437 } 00438 }
TransportAddress * BootstrapOracle::getRandomAliveNode | ( | uint32_t | nodeType = 0 |
) |
Selects a random node from the peerSet, which is not already marked for deletion.
nodeType | If != 0, return a node of that type |
Referenced by SimpleNetConfigurator::preKillNode(), and IPv4UnderlayConfigurator::preKillNode().
00441 { 00442 if (peerSet.size() <= preKilledNodes) { 00443 // all nodes are already marked for deletion; 00444 return NULL; 00445 } else { 00446 // return random address in O(log n) 00447 PeerHashMap::iterator it; 00448 bootstrapEntry tempEntry = {NULL, NULL}; 00449 00450 IPvXAddress randomAddr(intuniform(min_ip, max_ip)); 00451 00452 it = peerSet.find(randomAddr); 00453 00454 if (it == peerSet.end()) { 00455 it = peerSet.insert(std::make_pair(randomAddr,tempEntry)).first; 00456 peerSet.erase(it++); 00457 } 00458 00459 if (it == peerSet.end()) { 00460 it = peerSet.begin(); 00461 } 00462 00463 while ((nodeType && (it->second.info->getTypeID() != nodeType)) 00464 || it->second.info->isPreKilled()) { 00465 it++; 00466 if (it == peerSet.end()) { 00467 it = peerSet.begin(); 00468 } 00469 } 00470 00471 return it->second.node; 00472 } 00473 00474 return NULL; 00475 }
PeerInfo * BootstrapOracle::getRandomPeerInfo | ( | uint32_t | nodeType = 0 , |
|
bool | bootstrapNeeded = false | |||
) | [virtual] |
Selects a random node from the peerSet.
nodeType | If != 0, return a node of that type | |
bootstrapNeeded | does the node need to be bootstrapped? |
Referenced by mergeBootstrapNodes(), and IPv4UnderlayConfigurator::migrateNode().
00402 { 00403 // return random TransportAddress in O(log n) 00404 PeerHashMap::iterator it; 00405 bootstrapEntry tempEntry = {NULL, NULL}; 00406 00407 IPvXAddress randomAddr(intuniform(min_ip, max_ip)); 00408 00409 it = peerSet.find(randomAddr); 00410 if (it == peerSet.end()) { 00411 it = peerSet.insert(std::make_pair(randomAddr,tempEntry)).first; 00412 peerSet.erase(it++); 00413 } 00414 00415 if (it == peerSet.end()) 00416 it = peerSet.begin(); 00417 00418 // if nodeType != 0, search for next node with the given type 00419 if (nodeType) { 00420 while((nodeType && (it->second.info->getTypeID() != nodeType)) 00421 || (bootstrappedNeeded && !it->second.info->isBootstrapped())) { 00422 ++it; 00423 if (it == peerSet.end()) it = peerSet.begin(); 00424 } 00425 } 00426 00427 return it->second.info; 00428 }
PeerInfo * BootstrapOracle::getPeerInfo | ( | const IPvXAddress & | ip | ) | [virtual] |
Searches the peerSet for the specified node.
ip | IPvXAddress of the specified node |
00392 { 00393 PeerHashMap::iterator it = peerSet.find(ip); 00394 00395 if (it == peerSet.end()) 00396 return NULL; 00397 else 00398 return it->second.info; 00399 }
bool BootstrapOracle::areNodeTypesConnected | ( | uint32_t | a, | |
uint32_t | b | |||
) |
Referenced by SimpleUDP::processMsgFromApp().
00532 { 00533 if ((a > MAX_NODETYPES) || (b > MAX_NODETYPES)) { 00534 throw new cException("BootstrapOracle::areNodeTypesConnected(): nodeType " 00535 "bigger then MAX_NODETYPES"); 00536 } 00537 00538 return connectionMatrix[a][b]; 00539 }
void BootstrapOracle::connectNodeTypes | ( | uint32_t | a, | |
uint32_t | b | |||
) |
Referenced by GlobalTraceManager::handleMessage().
00542 { 00543 if ((a > MAX_NODETYPES) || (b > MAX_NODETYPES)) { 00544 throw new cException("BootstrapOracle::connectNodeTypes(): nodeType " 00545 "bigger then MAX_NODETYPES"); 00546 } 00547 00548 connectionMatrix[a][b]=true; 00549 00550 EV << "[BootstrapOracle::connectNodeTypes()]\n" 00551 << " Connecting " << a << "->" << b 00552 << endl; 00553 00554 }
void BootstrapOracle::disconnectNodeTypes | ( | uint32_t | a, | |
uint32_t | b | |||
) |
Referenced by GlobalTraceManager::handleMessage().
00557 { 00558 if ((a > MAX_NODETYPES) || (b > MAX_NODETYPES)) { 00559 throw new cException("BootstrapOracle::disconnectNodeTypes(): nodeType " 00560 "bigger then MAX_NODETYPES"); 00561 } 00562 00563 connectionMatrix[a][b]=false; 00564 00565 EV << "[BootstrapOracle::disconnectNodeTypes()]\n" 00566 << " Disconnecting " << a << "->" << b 00567 << endl; 00568 00569 }
void BootstrapOracle::mergeBootstrapNodes | ( | int | toPartition, | |
int | fromPartition, | |||
int | numNodes | |||
) |
Referenced by GlobalTraceManager::handleMessage().
00573 { 00574 BootstrapList* bootstrapList = 00575 check_and_cast<BootstrapList*>(simulation.module( 00576 getRandomPeerInfo(toPartition, false)->getModuleID())-> 00577 submodule("bootstrapList")); 00578 00579 bootstrapList->insertBootstrapCandidate(getRandomNode(fromPartition, true), 00580 DNSSD); 00581 }
void BootstrapOracle::initialize | ( | ) | [protected, virtual] |
Init member function of module.
00062 { 00063 maxNumberOfKeys = par("maxNumberOfKeys"); 00064 keyProbability = par("keyProbability"); 00065 WATCH_UNORDERED_MAP(peerSet); 00066 WATCH_VECTOR(keyList); 00067 WATCH(bootstrappedPeerSize); 00068 WATCH(bootstrappedMaliciousNodes); 00069 WATCH(maliciousNodes); 00070 createKeyList(maxNumberOfKeys); 00071 bootstrappedPeerSize = 0; 00072 for (int i = 0; i < MAX_NODETYPES; i++) 00073 bootstrappedPeerSizePerType[i] = 0; 00074 bootstrappedMaliciousNodes = 0; 00075 maliciousNodes = 0; 00076 preKilledNodes = 0; 00077 00078 if (par("maliciousNodeChange")) { 00079 if ((double) par("maliciousNodeProbability") > 0) 00080 error("maliciousNodeProbability and maliciousNodeChange are not supported concurrently"); 00081 00082 cMessage* msg = new cMessage("maliciousNodeChange"); 00083 scheduleAt(simulation.simTime() + (int) par("maliciousNodeChangeStartTime"), msg); 00084 maliciousNodesVector.setName("MaliciousNodeRate"); 00085 maliciousNodesVector.record(0); 00086 maliciousNodeRatio = 0; 00087 } 00088 00089 min_ip = 0xFFFFFFFF; 00090 max_ip = 0x00000000; 00091 00092 for (int i=0; i<MAX_NODETYPES; i++) { 00093 for (int j=0; j<MAX_NODETYPES; j++) { 00094 connectionMatrix[i][j] = true; 00095 } 00096 } 00097 00098 globalStatistics = GlobalStatisticsAccess().get(); 00099 00100 cMessage* timer = new cMessage("oracleTimer"); 00101 00102 scheduleAt(simulation.simTime(), timer); 00103 }
void BootstrapOracle::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
HandleMessage member function of module.
msg | messag to handle |
00106 { 00107 if (msg->isName("maliciousNodeChange")) { 00108 double newRatio = maliciousNodeRatio + (double) par("maliciousNodeChangeRate"); // ratio to obtain 00109 if (maliciousNodeRatio < (double) par("maliciousNodeChangeStartValue")) 00110 newRatio = (double) par("maliciousNodeChangeStartValue"); 00111 00112 if (newRatio < (double) par("maliciousNodeChangeStopValue")) // schedule next event 00113 scheduleAt(simulation.simTime() + (int) par("maliciousNodeChangeInterval"), msg); 00114 00115 int nodesNeeded = (int) (((double) par("maliciousNodeChangeRate")) * peerSet.size()); 00116 00117 EV << "[BootstrapOracle::handleMessage()]\n" 00118 << " Changing " << nodesNeeded << " nodes to be malicious" 00119 << endl; 00120 00121 for (int i = 0; i < nodesNeeded; i++) { 00122 // search a node that is not yet malicious 00123 NodeHandle node; 00124 do { 00125 node = getRandomNode(0, false); 00126 } while (isMalicious(node)); 00127 00128 setMalicious(node, true); 00129 } 00130 00131 maliciousNodesVector.record(newRatio); 00132 maliciousNodeRatio = newRatio; 00133 00134 return; 00135 } 00136 00137 else if (msg->isName("oracleTimer")) { 00138 RECORD_STATS(globalStatistics->recordOutVector( 00139 "BootstrapOracle: Number of nodes", peerSet.size())); 00140 scheduleAt(simulation.simTime() + 50, msg); 00141 } else { 00142 opp_error("BootstrapOracle::handleMessage: Unknown message type!"); 00143 } 00144 }
void BootstrapOracle::createKeyList | ( | uint | size | ) | [protected, virtual] |
Member function to create keylist.
size | size of new keylist |
Referenced by initialize().
00346 { 00347 for (uint i = 0; i < size; i++) 00348 keyList.push_back(OverlayKey::random()); 00349 }
KeyList BootstrapOracle::keyList [protected] |
uint BootstrapOracle::bootstrappedPeerSize [protected] |
number of bootstrapped peers in the peer set
Referenced by getRandomNode(), initialize(), killPeer(), registerPeer(), and removePeer().
uint BootstrapOracle::bootstrappedPeerSizePerType[MAX_NODETYPES] [protected] |
number of bootstrapped peers of all types
Referenced by getRandomNode(), initialize(), killPeer(), registerPeer(), and removePeer().
uint BootstrapOracle::bootstrappedMaliciousNodes [protected] |
number of bootstrapped malicious nodes in the peer set
Referenced by initialize(), killPeer(), registerPeer(), removePeer(), and setMalicious().
uint BootstrapOracle::maliciousNodes [protected] |
uint BootstrapOracle::preKilledNodes [protected] |
number of nodes marked for deletion in the peer set
Referenced by getRandomAliveNode(), initialize(), killPeer(), and setPreKilled().
double BootstrapOracle::maliciousNodeRatio [protected] |
ratio of current malicious nodes when changing the ratio dynamically
Referenced by addPeer(), handleMessage(), and initialize().
cOutVector BootstrapOracle::maliciousNodesVector [protected] |
vector that records the cange of malicious node rate
Referenced by handleMessage(), and initialize().
PeerHashMap BootstrapOracle::peerSet [protected] |
Set of nodes participating in the overlay.
Referenced by addPeer(), getBootstrapNode(), getPeerInfo(), getRandomAliveNode(), getRandomNode(), getRandomPeerInfo(), handleMessage(), initialize(), killPeer(), registerPeer(), removePeer(), sendNotificationToAllPeers(), and ~BootstrapOracle().
uint BootstrapOracle::maxNumberOfKeys [protected] |
double BootstrapOracle::keyProbability [protected] |
uint32 BootstrapOracle::min_ip [private] |
Referenced by addPeer(), getRandomAliveNode(), getRandomNode(), getRandomPeerInfo(), and initialize().
uint32 BootstrapOracle::max_ip [private] |
used for random node choosing
Referenced by addPeer(), getRandomAliveNode(), getRandomNode(), getRandomPeerInfo(), and initialize().
bool BootstrapOracle::connectionMatrix[MAX_NODETYPES][MAX_NODETYPES] [private] |
matrix specifices with node types (partitions) can communication
Referenced by areNodeTypesConnected(), connectNodeTypes(), disconnectNodeTypes(), getBootstrapNode(), and initialize().