#include <BootstrapOracle.h>
Public Types | |
typedef std::vector< OverlayKey > | KeyList |
Public Member Functions | |
virtual const NodeHandle & | getBootstrapNode () |
Returns a random node handle. | |
virtual void | registerPeer (const NodeHandle &peer) |
Adds new peers to the peer set. | |
virtual void | removePeer (const NodeHandle &peer) |
Removes a peer from the peer set. | |
virtual KeyList * | getKeyList (uint maximumKeys) |
Returns a keylist. | |
virtual const OverlayKey & | getRandomKeyListItem () const |
Returns random key from list. | |
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 | |
std::set< NodeHandle > | peerSet |
Set of nodes participating the overlay. | |
uint | maxNumberOfKeys |
parameter used by createKeyList() | |
double | keyProbability |
probability of keys to be owned by nodes |
typedef std::vector<OverlayKey> BootstrapOracle::KeyList |
void BootstrapOracle::createKeyList | ( | uint | size | ) | [protected, virtual] |
Member function to create keylist.
size | size of new keylist |
00084 { 00085 for(uint i = 0; i < size; i++) 00086 keyList.push_back(OverlayKey::random()); 00087 }
const NodeHandle & BootstrapOracle::getBootstrapNode | ( | ) | [virtual] |
Returns a random node handle.
Returns a random node handle from the peer set if at least one peer has been registered, and an empty node handle otherwise.
00048 { 00049 if(peerSet.size() == 0) 00050 return NodeHandle::UNSPECIFIED_NODE; 00051 else { 00052 // return random NodeHandle in O(log n) 00053 00054 //NodeHandle tmpHandle(OverlayKey::random(), IPvXAddress(), 0, 0); 00055 NodeHandle tmpHandle(OverlayKey::random(), 00056 IPAddress::UNSPECIFIED_ADDRESS, 0, 0); 00057 //std::set<NodeHandle>::iterator it = peerSet.find(tmpHandle); 00058 00059 //if (it == peerSet.end()) { 00060 //it = peerSet.insert(tmpHandle).first; 00061 std::set 00062 <NodeHandle>::iterator it = peerSet.insert(tmpHandle).first; 00063 peerSet.erase(it++); 00064 00065 if (it == peerSet.end()) 00066 it = peerSet.begin(); 00067 //} 00068 00069 return *it; 00070 } 00071 }
BootstrapOracle::KeyList * BootstrapOracle::getKeyList | ( | uint | maximumKeys | ) | [virtual] |
Returns a keylist.
maximumKeys | maximum number of keys in new keylist |
00090 { 00091 // copy keylist to temporary keylist 00092 KeyList tmpKeyList; 00093 tmpKeyList.clear(); 00094 for ( uint i=0; i < keyList.size(); i++ ) 00095 tmpKeyList.push_back(keyList[i]); 00096 00097 KeyList* returnList = new KeyList; 00098 00099 for ( uint i=0; i < ((float)maximumKeys * keyProbability); i++) { 00100 uint index = intuniform(0, tmpKeyList.size()-1); 00101 returnList->push_back(tmpKeyList[index]); 00102 tmpKeyList.erase(tmpKeyList.begin()+index); 00103 } 00104 00105 return returnList; 00106 }
const OverlayKey & BootstrapOracle::getRandomKeyListItem | ( | ) | const [virtual] |
void BootstrapOracle::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
void BootstrapOracle::initialize | ( | ) | [protected, virtual] |
Init member function of module.
00034 { 00035 maxNumberOfKeys = par("maxNumberOfKeys"); 00036 keyProbability = par("keyProbability"); 00037 WATCH_SET(peerSet); 00038 WATCH_VECTOR(keyList); 00039 createKeyList(maxNumberOfKeys); 00040 }
void BootstrapOracle::registerPeer | ( | const NodeHandle & | peer | ) | [virtual] |
Adds new peers to the peer set.
peer | node to register |
00074 { 00075 peerSet.insert(peer); 00076 }
void BootstrapOracle::removePeer | ( | const NodeHandle & | peer | ) | [virtual] |
Removes a peer from the peer set.
peer | node to remove |
00079 { 00080 peerSet.erase(peer); 00081 }
KeyList BootstrapOracle::keyList [protected] |
the keylist
double BootstrapOracle::keyProbability [protected] |
probability of keys to be owned by nodes
uint BootstrapOracle::maxNumberOfKeys [protected] |
parameter used by createKeyList()
std::set<NodeHandle> BootstrapOracle::peerSet [protected] |
Set of nodes participating the overlay.