#include <BootstrapOracle.h>
Public Types | |
typedef std::vector< OverlayKey > | KeyList |
Public Member Functions | |
void | addPeer (const IPvXAddress &addr, PeerInfo *info) |
Adds new peers to the peer set. | |
virtual void | killPeer (const IPvXAddress &ip) |
Removes a peer from the peer set. | |
virtual const NodeHandle & | getBootstrapNode () |
Returns a random transport address. | |
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 PeerInfo * | getPeerInfo (const TransportAddress &peer) |
Returns peer information corresponding to a 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 | |
uint | bootstrappedPeerSize |
number of bootstrapped peers in the peer set | |
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 |
typedef std::vector<OverlayKey> BootstrapOracle::KeyList |
typedef __gnu_cxx::hash_map<IPvXAddress, bootstrapEntry> BootstrapOracle::PeerHashMap [protected] |
Set of nodes participating in the overlay.
void BootstrapOracle::addPeer | ( | const IPvXAddress & | addr, | |
PeerInfo * | info | |||
) |
Adds new peers to the peer set.
Called automatically by the underlay, when new peers are created.
peer | node to add |
00088 { 00089 bootstrapEntry temp; 00090 temp.node = new TransportAddress(addr); 00091 temp.info = info; 00092 peerSet.insert(std::make_pair(addr, temp)); 00093 }
void BootstrapOracle::createKeyList | ( | uint | size | ) | [protected, virtual] |
Member function to create keylist.
size | size of new keylist |
00167 { 00168 for(uint i = 0; i < size; i++) 00169 keyList.push_back(OverlayKey::random()); 00170 }
const NodeHandle & BootstrapOracle::getBootstrapNode | ( | ) | [virtual] |
Returns a random transport address.
Returns a random transport address from the peer set if at least one peer has been registered, and an empty transport address otherwise.
00058 { 00059 if(bootstrappedPeerSize == 0) 00060 return NodeHandle::UNSPECIFIED_NODE; 00061 else { 00062 // return random TransportAddress in O(log n) 00063 PeerHashMap::iterator it = peerSet.end(); 00064 bootstrapEntry tempEntry = {NULL, NULL}; 00065 00066 while(it == peerSet.end() || !it->second.info->isBootstrapped()) { 00067 IPvXAddress randomAddr(intuniform(0,0xFFFFFFFF)); 00068 00069 it = peerSet.find(randomAddr); 00070 00071 if (it == peerSet.end()) { 00072 it = peerSet.insert(std::make_pair(randomAddr,tempEntry)).first; 00073 peerSet.erase(it++); 00074 } 00075 00076 if (it == peerSet.end()) 00077 it = peerSet.begin(); 00078 } 00079 00080 if(dynamic_cast<NodeHandle*>(it->second.node)) 00081 return *dynamic_cast<NodeHandle*>(it->second.node); 00082 else 00083 return NodeHandle::UNSPECIFIED_NODE; 00084 } 00085 }
BootstrapOracle::KeyList * BootstrapOracle::getKeyList | ( | uint | maximumKeys | ) | [virtual] |
Returns a keylist.
maximumKeys | maximum number of keys in new keylist |
00173 { 00174 if (maximumKeys > keyList.size()) { 00175 maximumKeys = keyList.size(); 00176 } 00177 // copy keylist to temporary keylist 00178 KeyList tmpKeyList; 00179 tmpKeyList.clear(); 00180 for ( uint i=0; i < keyList.size(); i++ ) 00181 tmpKeyList.push_back(keyList[i]); 00182 00183 KeyList* returnList = new KeyList; 00184 00185 for ( uint i=0; i < ((float)maximumKeys * keyProbability); i++) { 00186 uint index = intuniform(0, tmpKeyList.size()-1); 00187 returnList->push_back(tmpKeyList[index]); 00188 tmpKeyList.erase(tmpKeyList.begin()+index); 00189 } 00190 00191 return returnList; 00192 }
PeerInfo * BootstrapOracle::getPeerInfo | ( | const TransportAddress & | peer | ) | [virtual] |
Returns peer information corresponding to a specified node.
Returns a random transport address from the peer set if at least one peer has been registered, and an empty transport address otherwise.
00200 { 00201 PeerHashMap::iterator it = peerSet.find(peer.ip); 00202 if(it == peerSet.end()) 00203 return NULL; 00204 else 00205 return it->second.info; 00206 }
const OverlayKey & BootstrapOracle::getRandomKeyListItem | ( | ) | const [virtual] |
void BootstrapOracle::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
void BootstrapOracle::initialize | ( | ) | [protected, virtual] |
Init member function of module.
00042 { 00043 maxNumberOfKeys = par("maxNumberOfKeys"); 00044 keyProbability = par("keyProbability"); 00045 //WATCH_MAP(peerSet); 00046 WATCH_VECTOR(keyList); 00047 WATCH(bootstrappedPeerSize); 00048 createKeyList(maxNumberOfKeys); 00049 bootstrappedPeerSize = 0; 00050 }
void BootstrapOracle::killPeer | ( | const IPvXAddress & | ip | ) | [virtual] |
Removes a peer from the peer set.
Called automatically by the underlay, when peers are removed.
peer | node to remove |
00153 { 00154 PeerHashMap::iterator it = peerSet.find(ip); 00155 if(it != peerSet.end()) { 00156 if (it->second.info->isBootstrapped()) 00157 bootstrappedPeerSize--; 00158 00159 it->second.info->setBootstrapped(false); 00160 delete it->second.node; 00161 delete it->second.info; 00162 peerSet.erase(it); 00163 } 00164 }
void BootstrapOracle::registerPeer | ( | const NodeHandle & | peer | ) | [virtual] |
Bootstraps peers in the peer set.
peer | node to register |
00120 { 00121 PeerHashMap::iterator it = peerSet.find(peer.ip); 00122 if (it == peerSet.end()) 00123 error("unable to bootstrap peer, peer is not in peer set"); 00124 else { 00125 PeerInfo* info = it->second.info; 00126 00127 if (!info->isBootstrapped()) 00128 bootstrappedPeerSize++; 00129 00130 info->setBootstrapped(); 00131 delete it->second.node; 00132 peerSet.erase(it); 00133 00134 bootstrapEntry temp; 00135 temp.node = new NodeHandle(peer); 00136 temp.info = info; 00137 peerSet.insert(std::make_pair(temp.node->ip, temp)); 00138 } 00139 }
void BootstrapOracle::registerPeer | ( | const TransportAddress & | peer | ) | [virtual] |
Bootstraps peers in the peer set.
peer | node to register |
00096 { 00097 PeerHashMap::iterator it = peerSet.find(peer.ip); 00098 if (it == peerSet.end()) 00099 error("unable to bootstrap peer, peer is not in peer set"); 00100 else { 00101 PeerInfo* info = it->second.info; 00102 00103 if (!info->isBootstrapped()) 00104 bootstrappedPeerSize++; 00105 00106 info->setBootstrapped(); 00107 00108 delete it->second.node; 00109 peerSet.erase(it); 00110 00111 bootstrapEntry temp; 00112 temp.node = new TransportAddress(peer); 00113 temp.info = info; 00114 peerSet.insert(std::make_pair(temp.node->ip, temp)); 00115 bootstrappedPeerSize++; 00116 } 00117 }
void BootstrapOracle::removePeer | ( | const TransportAddress & | peer | ) | [virtual] |
Debootstraps peers in the peer set.
peer | node to remove |
00142 { 00143 PeerHashMap::iterator it = peerSet.find(peer.ip); 00144 if(it != peerSet.end()) { 00145 if (it->second.info->isBootstrapped()) 00146 bootstrappedPeerSize--; 00147 00148 it->second.info->setBootstrapped(false); 00149 } 00150 }
uint BootstrapOracle::bootstrappedPeerSize [protected] |
number of bootstrapped peers in the peer set
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()
PeerHashMap BootstrapOracle::peerSet [protected] |
Set of nodes participating in the overlay.