BootstrapOracle Class Reference

#include <BootstrapOracle.h>

List of all members.


Detailed Description

Global modul that supports bootstrap process and key distribution.

Author:
Markus Mauch, Robert Palmer


Public Types

typedef std::vector< OverlayKeyKeyList
 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.
virtual void killPeer (const IPvXAddress &ip)
 Removes a peer from the peerSet.
virtual const NodeHandlegetRandomNode (bool bootstrappedNeeded)
 Returns a random NodeHandle.
virtual const NodeHandlegetBootstrapNode ()
 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 KeyListgetKeyList (uint maximumKeys)
 Returns a keylist.
virtual DataMapgetDataMap ()
virtual const OverlayKeygetRandomKeyListItem () 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 PeerInfogetPeerInfo (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 PeerInfogetRandomPeerInfo (uint32_t nodeType=0)
 Selects a random node from the peerSet.
virtual PeerInfogetPeerInfo (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
GlobalStatisticsglobalStatistics
 pointer to GlobalStatistics module in this node


Member Typedef Documentation

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.


Member Function Documentation

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.

Parameters:
addr IPvXAddress of the peer to add
info underlay specific info of the peer to add
00172 {
00173     bootstrapEntry temp;
00174     temp.node = new TransportAddress(ip);
00175     temp.info = info;
00176     peerSet.insert(std::make_pair(temp.node->ip, temp));
00177     // set bounds for random node retrival
00178     if(ip.get4().getInt() < min_ip) min_ip = ip.get4().getInt();
00179     if(ip.get4().getInt() > max_ip) max_ip = ip.get4().getInt();
00180 
00181     if (uniform(0, 1) < (double) par("maliciousNodeProbability") ||
00182        (par("maliciousNodeChange") && uniform(0, 1) < maliciousNodeRatio))
00183         setMalicious(*temp.node, true);
00184 }

void BootstrapOracle::killPeer ( const IPvXAddress &  ip  )  [virtual]

Removes a peer from the peerSet.

Called automatically by the underlay, when peers are removed.

Parameters:
ip IPvXAddress of the peer to remove
00250 {
00251     PeerHashMap::iterator it = peerSet.find(ip);
00252     if(it != peerSet.end()) {
00253         if(it->second.info->isBootstrapped()) {
00254             bootstrappedPeerSize--;
00255             if(it->second.info->isMalicious())
00256                 bootstrappedMaliciousNodes--;
00257             it->second.info->setBootstrapped(false);
00258         }
00259 
00260         delete it->second.node;
00261         delete it->second.info;
00262         peerSet.erase(it);
00263     }
00264 }

const NodeHandle & BootstrapOracle::getRandomNode ( bool  bootstrappedNeeded  )  [virtual]

Returns a random NodeHandle.

Returns a random NodeHandle from the peerSet if at least one peer has been registered, an empty TransportAddress otherwise.

Parameters:
bootstrappedNeeded does the node need to be bootstrapped?
Returns:
NodeHandle of the node
00140 {
00141         if (peerSet.size() == 0)
00142                 return NodeHandle::UNSPECIFIED_NODE;
00143         if (bootstrappedNeeded && bootstrappedPeerSize == 0)
00144                 return NodeHandle::UNSPECIFIED_NODE;
00145         else {
00146         // return random TransportAddress in O(log n)
00147                 PeerHashMap::iterator it = peerSet.end();
00148                 bootstrapEntry tempEntry = {NULL, NULL};
00149 
00150                 while(it == peerSet.end() || (bootstrappedNeeded && !it->second.info->isBootstrapped())) {
00151             IPvXAddress randomAddr(intuniform(min_ip, max_ip));
00152 
00153                         it = peerSet.find(randomAddr);
00154 
00155                         if (it == peerSet.end()) {
00156                                 it = peerSet.insert(std::make_pair(randomAddr,tempEntry)).first;
00157                                 peerSet.erase(it++);
00158                         }
00159 
00160                         if (it == peerSet.end())
00161                                 it = peerSet.begin();
00162                 }
00163 
00164                 if(dynamic_cast<NodeHandle*>(it->second.node))
00165                         return *dynamic_cast<NodeHandle*>(it->second.node);
00166                 else
00167                         return NodeHandle::UNSPECIFIED_NODE;
00168         }
00169 }

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.

Returns:
NodeHandle of the node
00135 {
00136     return getRandomNode(true);
00137 }

void BootstrapOracle::registerPeer ( const TransportAddress peer  )  [virtual]

Bootstraps peers in the peer set.

Parameters:
peer node to register
00187 {
00188     PeerHashMap::iterator it = peerSet.find(peer.ip);
00189     if (it == peerSet.end())
00190         error("unable to bootstrap peer, peer is not in peer set");
00191     else {
00192         PeerInfo* info = it->second.info;
00193 
00194         if (!info->isBootstrapped()) {
00195             bootstrappedPeerSize++;
00196             info->setBootstrapped();
00197             if (info->isMalicious())
00198                 bootstrappedMaliciousNodes++;
00199         }
00200 
00201         delete it->second.node;
00202         peerSet.erase(it);
00203 
00204         bootstrapEntry temp;
00205         temp.node = new TransportAddress(peer);
00206         temp.info = info;
00207         peerSet.insert(std::make_pair(temp.node->ip, temp));
00208     }
00209 }

void BootstrapOracle::registerPeer ( const NodeHandle peer  )  [virtual]

Bootstraps peers in the peer set.

Parameters:
peer node to register
00212 {
00213     PeerHashMap::iterator it = peerSet.find(peer.ip);
00214     if (it == peerSet.end())
00215         error("unable to bootstrap peer, peer is not in peer set");
00216     else {
00217         PeerInfo* info = it->second.info;
00218 
00219         if (!info->isBootstrapped()) {
00220             bootstrappedPeerSize++;
00221             info->setBootstrapped();
00222             if (info->isMalicious())
00223                 bootstrappedMaliciousNodes++;
00224         }
00225 
00226         delete it->second.node;
00227         peerSet.erase(it);
00228 
00229         bootstrapEntry temp;
00230         temp.node = new NodeHandle(peer);
00231         temp.info = info;
00232         peerSet.insert(std::make_pair(temp.node->ip, temp));
00233     }
00234 }

void BootstrapOracle::removePeer ( const TransportAddress peer  )  [virtual]

Debootstraps peers in the peer set.

Parameters:
peer node to remove
00237 {
00238     PeerHashMap::iterator it = peerSet.find(peer.ip);
00239         if(it != peerSet.end() && it->second.info->isBootstrapped()) {
00240                 bootstrappedPeerSize--;
00241                 it->second.info->setBootstrapped(false);
00242 
00243         if(it->second.info->isMalicious())
00244             bootstrappedMaliciousNodes--;
00245         it->second.info->setBootstrapped(false);
00246     }
00247 }

BootstrapOracle::KeyList * BootstrapOracle::getKeyList ( uint  maximumKeys  )  [virtual]

Returns a keylist.

Parameters:
maximumKeys maximum number of keys in new keylist
Returns:
pointer to new keylist
00278 {
00279     if (maximumKeys > keyList.size()) {
00280         maximumKeys = keyList.size();
00281     }
00282     // copy keylist to temporary keylist
00283     KeyList tmpKeyList;
00284     tmpKeyList.clear();
00285     for ( uint i=0; i < keyList.size(); i++ )
00286         tmpKeyList.push_back(keyList[i]);
00287 
00288     KeyList* returnList = new KeyList;
00289 
00290     for ( uint i=0; i < ((float)maximumKeys * keyProbability); i++) {
00291         uint index = intuniform(0, tmpKeyList.size()-1);
00292         returnList->push_back(tmpKeyList[index]);
00293         tmpKeyList.erase(tmpKeyList.begin()+index);
00294     }
00295 
00296     return returnList;
00297 }

BootstrapOracle::DataMap * BootstrapOracle::getDataMap (  )  [virtual]

00273 {
00274     return &dataMap;
00275 }

const OverlayKey & BootstrapOracle::getRandomKeyListItem (  )  const [virtual]

Returns random key from list.

Returns:
the key
00300 {
00301     return keyList[intuniform(0,keyList.size()-1)];
00302 }

void BootstrapOracle::setOverlayReadyIcon ( const TransportAddress address,
bool  ready 
) [virtual]

Colors module-icon blue (ready), green (ready, malicious) or red (not ready).

Parameters:
address TransportAddress of the specified node
ready state to visualize
00379 {
00380         if (ev.isGUI()) {
00381                 const char* color;
00382                 if (ready) {
00383                         color = isMalicious(address) ? "green" : ""; // change color if node is malicious
00384                 } else {
00385                         color = "red";
00386                 }
00387                 
00388                 cModule* module = simulation.module(getPeerInfo(address)->getModuleID());
00389                 
00390                 module->parentModule()->displayString().setTagArg("i2", 1, color);
00391                 module->displayString().setTagArg("i", 1, color);
00392         }
00393 }

PeerInfo * BootstrapOracle::getPeerInfo ( const TransportAddress peer  )  [virtual]

Searches the peerSet for the specified node.

Parameters:
peer TransportAddress of the specified node
Returns:
PeerInfo of the node or NULL if node is not in peerSet
00305 {
00306     PeerHashMap::iterator it = peerSet.find(peer.ip);
00307     if(it == peerSet.end())
00308         return NULL;
00309     else
00310         return it->second.info;
00311 }

void BootstrapOracle::setMalicious ( const TransportAddress address,
bool  malicious 
) [virtual]

Set a node to be malicious.

Parameters:
address TransportAddress of the node
malicious state to set
00349 {
00350     PeerInfo* peer = getPeerInfo(address);
00351     if(peer != NULL)
00352     {
00353         if(malicious && !peer->isMalicious())
00354                 {
00355                         maliciousNodes++;
00356                         if (peer->isBootstrapped())
00357                                 bootstrappedMaliciousNodes++;
00358                 }
00359                 if (!malicious && peer->isMalicious())
00360                 {
00361                         maliciousNodes--;
00362                         if (peer->isBootstrapped())
00363                                 bootstrappedMaliciousNodes--;
00364                 }
00365         peer->setMalicious(malicious);
00366     }
00367 }

bool BootstrapOracle::isMalicious ( const TransportAddress address  )  [virtual]

Check if a node is malicious.

Parameters:
address TransportAddress of the node
Returns:
if the node is malicious
00370 {
00371     PeerInfo* peer = getPeerInfo(address);
00372     if(peer != NULL)
00373         return peer->isMalicious();
00374 
00375     return false;
00376 }

PeerInfo * BootstrapOracle::getRandomPeerInfo ( uint32_t  nodeType = 0  )  [virtual]

Selects a random node from the peerSet.

Parameters:
type If != 0, return a node of that type
Returns:
The peerInfo of a random node
00322                                                               {
00323     // return random TransportAddress in O(log n)
00324     PeerHashMap::iterator it;
00325     bootstrapEntry tempEntry = {NULL, NULL};
00326 
00327     IPvXAddress randomAddr(intuniform(min_ip, max_ip));
00328 
00329     it = peerSet.find(randomAddr);
00330     if (it == peerSet.end()) {
00331         it = peerSet.insert(std::make_pair(randomAddr,tempEntry)).first;
00332         peerSet.erase(it++);
00333     }
00334     if (it == peerSet.end())
00335         it = peerSet.begin();
00336 
00337     // if nodeType != 0, search for next node with the given type
00338     if (nodeType) {
00339         while( it->second.info->getTypeID() != nodeType ) {
00340             ++it;
00341             if (it == peerSet.end()) it = peerSet.begin();
00342         }
00343     }
00344 
00345     return it->second.info;
00346 }

PeerInfo * BootstrapOracle::getPeerInfo ( const IPvXAddress &  ip  )  [virtual]

Searches the peerSet for the specified node.

Parameters:
ip IPvXAddress of the specified node
Returns:
PeerInfo of the node or NULL if node is not in peerSet
00314 {
00315     PeerHashMap::iterator it = peerSet.find(ip);
00316     if(it == peerSet.end())
00317         return NULL;
00318     else
00319         return it->second.info;
00320 }

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         {
00074                 if ((double) par("maliciousNodeProbability") > 0)
00075                         error("maliciousNodeProbability and maliciousNodeChange are not supported concurrently");
00076                 
00077                 cMessage* msg = new cMessage("maliciousNodeChange");
00078                 scheduleAt(simulation.simTime() + (int) par("maliciousNodeChangeStartTime"), msg);
00079                 maliciousNodesVector.setName("MaliciousNodeRate");
00080                 maliciousNodesVector.record(0);
00081                 maliciousNodeRatio = 0;
00082         }
00083 
00084     min_ip =0xFFFFFFFF;
00085     max_ip =0x00000000;
00086 
00087     globalStatistics = GlobalStatisticsAccess().get();
00088 
00089     cMessage* timer = new cMessage("oracleTimer");
00090 
00091     scheduleAt(simulation.simTime(), timer);
00092 }

void BootstrapOracle::handleMessage ( cMessage *  msg  )  [protected, virtual]

HandleMessage member function of module.

Parameters:
msg messag to handle
00095 {
00096         if (msg->isName("maliciousNodeChange"))
00097         {
00098                 double newRatio = maliciousNodeRatio + (double) par("maliciousNodeChangeRate"); // ratio to obtain
00099                 if (maliciousNodeRatio < (double) par("maliciousNodeChangeStartValue"))
00100                         newRatio = (double) par("maliciousNodeChangeStartValue");
00101                 
00102                 if (newRatio < (double) par("maliciousNodeChangeStopValue")) // schedule next event
00103                         scheduleAt(simulation.simTime() + (int) par("maliciousNodeChangeInterval"), msg);
00104 
00105                 int nodesNeeded = (int) (((double) par("maliciousNodeChangeRate")) * peerSet.size());
00106 
00107                 EV << "BootstrapOracle: Changing " << nodesNeeded << " Nodes to be malicious\n";
00108                 
00109                 for (int i = 0; i < nodesNeeded; i++)
00110                 {
00111                         // search a node that is not yet malicious
00112                         NodeHandle node;
00113                         do node = getRandomNode(false);
00114                         while (isMalicious(node));
00115 
00116                         setMalicious(node, true);
00117                 }
00118 
00119                 maliciousNodesVector.record(newRatio);
00120                 maliciousNodeRatio = newRatio;
00121                 
00122                 return;
00123         }
00124 
00125     else if (msg->isName("oracleTimer")) {
00126         RECORD_STATS(globalStatistics->recordOutVector(
00127                          "BootstrapOracle: Number of nodes", peerSet.size()));
00128         scheduleAt(simulation.simTime() + 10, msg);
00129     } else {
00130         opp_error("BootstrapOracle::handleMessage: Unknown message type!");
00131     }
00132 }

void BootstrapOracle::createKeyList ( uint  size  )  [protected, virtual]

Member function to create keylist.

Parameters:
size size of new keylist
00267 {
00268     for(uint i = 0; i < size; i++)
00269         keyList.push_back(OverlayKey::random());
00270 }


Member Data Documentation

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

GlobalStatistics* BootstrapOracle::globalStatistics [private]

pointer to GlobalStatistics module in this node


The documentation for this class was generated from the following files:
Generated on Tue Jul 24 16:51:18 2007 for ITM OverSim by  doxygen 1.5.1