The BootstrapList module maintains a list of bootstrap node candidates. More...
#include <BootstrapList.h>
Public Member Functions | |
BootstrapList () | |
~BootstrapList () | |
const TransportAddress | getBootstrapNode () |
Get a bootstrap node from the bootstrap list. | |
void | locateBootstrapNode (const NodeHandle &node) |
Determine locality of a bootstrap node. | |
bool | insertBootstrapCandidate (const NodeHandle &node, BootstrapNodePrioType prio=DNSSD) |
Inserts a new bootstrap candidate into the bootstrap list. | |
bool | insertBootstrapCandidate (BootstrapNodeHandle &node) |
void | removeBootstrapCandidate (const TransportAddress &addr) |
Remove an unavailable bootstrap candidate from the bootstraplist. | |
void | removeBootstrapNode (const NodeHandle &node) |
void | registerBootstrapNode (const NodeHandle &node) |
Protected Member Functions | |
virtual void | pingResponse (PingResponse *pingResponse, cPolymorphic *context, int rpcId, simtime_t rtt) |
virtual void | pingTimeout (PingCall *pingCall, const TransportAddress &dest, cPolymorphic *context, int rpcId) |
virtual CompType | getThisCompType () |
Private Member Functions | |
virtual void | initializeApp (int stage) |
initializes derived class-attributes | |
virtual void | finishApp () |
collects statistical data of derived app | |
void | handleTimerEvent (cMessage *msg) |
void | handleBootstrapListTimerExpired () |
Periodic maintenance method for the bootstrap list. | |
void | handleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt) |
void | handleLookupResponse (LookupResponse *msg) |
Handle the response for a lookup rpc. | |
Private Attributes | |
BootstrapNodeSet | bootstrapList |
cMessage * | timerMsg |
self-message for periodic maintenance | |
ZeroconfConnector * | zeroconfConnector |
pointer to the ZeroconfConnector module | |
bool | mergeOverlayPartitions |
if true, detect and merge overlay partitions | |
bool | maintainList |
maintain a list of bootstrap candidates and check them periodically | |
Static Private Attributes | |
static const int | timerInterval = 10 |
the interval of the maintenance timer in seconds |
The BootstrapList module maintains a list of bootstrap node candidates.
The BootstrapList module maintains a list of bootstrap node candidates received from various sources (GlobalNodeList for simulations and ZeroconfConnector for SingleHostUnderlay). This list is also used to detect overlay partitions and triggers the merging process.
Definition at line 53 of file BootstrapList.h.
BootstrapList::BootstrapList | ( | ) |
Definition at line 59 of file BootstrapList.cc.
{ zeroconfConnector = NULL; timerMsg = NULL; }
BootstrapList::~BootstrapList | ( | ) |
Definition at line 66 of file BootstrapList.cc.
{ cancelAndDelete(timerMsg); }
void BootstrapList::finishApp | ( | ) | [private, virtual] |
collects statistical data of derived app
Reimplemented from BaseApp.
Definition at line 376 of file BootstrapList.cc.
{ // dump the list of bootstrap nodes into the local cache only when // using SingleHostUnderlayConfigurator if (zeroconfConnector) { ofstream nodeListFile("nodelist.dat", ios::out|ios::trunc); if (!nodeListFile) { std::cerr << "nodelist.dat could not be opened" << endl; } else { for (BootstrapNodeSet::iterator iter = bootstrapList.begin(); iter != bootstrapList.end(); iter++) { nodeListFile << iter->second->getIp().str() << ' ' << iter->second->getPort() << ' ' << iter->second->getKey().toString(16) << '\n'; } nodeListFile.close(); } } // delete all bootstrap nodes and clear the list for (BootstrapNodeSet::iterator iter = bootstrapList.begin(); iter != bootstrapList.end(); iter++) { delete iter->second; } bootstrapList.clear(); }
const TransportAddress BootstrapList::getBootstrapNode | ( | ) |
Get a bootstrap node from the bootstrap list.
If not using SingleHostUnderlayConfigurator and the list is empty, return a node by asking the GlobalNodeList.
Definition at line 236 of file BootstrapList.cc.
Referenced by BasePastry::baseChangeState(), oversim::Nice::changeState(), Gia::changeState(), oversim::Chord::changeState(), Broose::changeState(), NTree::handleAppMessage(), Vast::handleJoin(), Quon::handleJoin(), and Kademlia::joinOverlay().
{ if (!maintainList) { // TODO: add a parameter to return malicious bootstrap nodes also return overlay->globalNodeList->getRandomNode(-1, true, true); // return overlay->globalNodeList->getBootstrapNode(); } else { const NodeHandle *bootstrapNode = &NodeHandle::UNSPECIFIED_NODE; int i, j = 0; // pick a random node from the list if (!bootstrapList.empty()) { i = intrand(bootstrapList.size()); BootstrapNodeSet::iterator iter = bootstrapList.begin(); while (j < i) { iter++; j++; } bootstrapNode = (NodeHandle *)iter->second; } else { // if the list empty, get a bootstrap node from GlobalNodeList if (!zeroconfConnector) bootstrapNode = &overlay->globalNodeList-> getBootstrapNode(overlay->getThisNode()); } return *bootstrapNode; } }
virtual CompType BootstrapList::getThisCompType | ( | ) | [inline, protected, virtual] |
Reimplemented from BaseApp.
Definition at line 110 of file BootstrapList.h.
{ return BOOTSTRAPLIST_COMP; };
void BootstrapList::handleBootstrapListTimerExpired | ( | ) | [private] |
Periodic maintenance method for the bootstrap list.
Definition at line 139 of file BootstrapList.cc.
Referenced by handleTimerEvent().
{ simtime_t current = simTime(); BootstrapNodeHandle *node; BootstrapNodeSet::iterator iter; for (iter = bootstrapList.begin(); iter != bootstrapList.end(); iter++) { node = iter->second; if (timerInterval <= SIMTIME_DBL(current - node->getLastPing())) { pingNode(*node); } } }
void BootstrapList::handleLookupResponse | ( | LookupResponse * | msg | ) | [private] |
Handle the response for a lookup rpc.
This is used to detected foreign overlay partitions
msg | The lookup response message |
Definition at line 171 of file BootstrapList.cc.
Referenced by handleRpcResponse().
{ EV << "[BootstrapList::handleLookupResponse() @ " << overlay->getThisNode().getIp() << " (" << overlay->getThisNode().getKey().toString(16) << ")]\n" << " Lookup response for key " << msg->getKey()<< " : "; if (msg->getIsValid()) { for (uint32_t i=0; i<msg->getSiblingsArraySize(); i++) { if (msg->getSiblings(i).getKey() == msg->getKey()) { EV << "Key " << msg->getSiblings(i) << "belongs to a local node." << endl; return; } } EV << "New partition discovered, going to join." << endl; BootstrapNodeSet::iterator iter; for (iter = bootstrapList.begin(); iter != bootstrapList.end(); iter++) { if (iter->second->getKey() == msg->getKey()) overlay->joinForeignPartition(*iter->second); } } else { EV << "failed" << endl; } return; }
void BootstrapList::handleRpcResponse | ( | BaseResponseMessage * | msg, | |
cPolymorphic * | context, | |||
int | rpcId, | |||
simtime_t | rtt | |||
) | [private] |
Definition at line 154 of file BootstrapList.cc.
{ RPC_SWITCH_START(msg) RPC_ON_RESPONSE(Lookup) { handleLookupResponse(_LookupResponse); EV << "[BootstrapList::handleRpcResponse() @ " << overlay->getThisNode().getIp() << " (" << overlay->getThisNode().getKey().toString(16) << ")]\n" << " Lookup RPC Response received: id=" << rpcId << "\n" << " msg=" << *_LookupResponse << " rtt=" << rtt << endl; } RPC_SWITCH_END( ) }
void BootstrapList::handleTimerEvent | ( | cMessage * | msg | ) | [private] |
Definition at line 128 of file BootstrapList.cc.
{ if (msg == timerMsg) { handleBootstrapListTimerExpired(); scheduleAt(simTime() + timerInterval, msg); } else { throw cRuntimeError("BootstrapList::handleTimerEvent(): " "Received unknown self-message!"); } }
void BootstrapList::initializeApp | ( | int | stage | ) | [private, virtual] |
initializes derived class-attributes
stage | the init stage |
Reimplemented from BaseApp.
Definition at line 72 of file BootstrapList.cc.
{ if (stage != MIN_STAGE_COMPONENTS) { return; } mergeOverlayPartitions = par("mergeOverlayPartitions"); maintainList = par("maintainList"); if (getParentModule()->getParentModule()->getSubmodule("zeroconfConnector", 0)) { zeroconfConnector = check_and_cast<ZeroconfConnector *>(getParentModule()-> getParentModule()->getSubmodule("zeroconfConnector", 0)); if (!zeroconfConnector->isEnabled()) { zeroconfConnector = NULL; } } // load local cache list only when using SingleHostUnderlayConfigurator if (zeroconfConnector) { ifstream nodeListFile("nodelist.dat", ios::in); if (!nodeListFile) { EV << "[BootstrapList::initializeApp() @ " << overlay->getThisNode().getIp() << " (" << overlay->getThisNode().getKey() << ")]\n" << " nodelist.dat not found" << endl; } else { char address[16]; int port; string key; BootstrapNodeHandle *node; while (nodeListFile >> address >> port >> key) { node = new BootstrapNodeHandle(OverlayKey(key, 16), IPvXAddress(address), port, CACHE); if (node) insertBootstrapCandidate(*node); } nodeListFile.close(); //TODO if (bootstrapList.size()) sendReadyMessage(); } } else { sendReadyMessage(); } WATCH_UNORDERED_MAP(bootstrapList); if (maintainList) { timerMsg = new cMessage("BootstrapListTimer"); scheduleAt(simTime() + timerInterval, timerMsg); } }
bool BootstrapList::insertBootstrapCandidate | ( | const NodeHandle & | node, | |
BootstrapNodePrioType | prio = DNSSD | |||
) |
Inserts a new bootstrap candidate into the bootstrap list.
node | the bootstrap candidate | |
prio | priority of the bootstrap node |
Definition at line 285 of file BootstrapList.cc.
Referenced by initializeApp(), and GlobalNodeList::mergeBootstrapNodes().
{ Enter_Method_Silent(); BootstrapNodeSet::iterator iter; BootstrapNodeHandle *bootstrapNode; // if node already in the list, update its lastPing and nodePrio fields if ((iter = bootstrapList.find(node)) != bootstrapList.end()) { iter->second->setLastPing(simTime()); iter->second->setNodePrio(prio); return true; } if ((bootstrapNode = new BootstrapNodeHandle(node, prio))) { bootstrapNode->setLastPing(simTime()); bootstrapList.insert(NodePair(*bootstrapNode, bootstrapNode)); } locateBootstrapNode(node); return false; }
bool BootstrapList::insertBootstrapCandidate | ( | BootstrapNodeHandle & | node | ) |
Definition at line 312 of file BootstrapList.cc.
{ Enter_Method_Silent(); BootstrapNodeSet::iterator iter; node.setLastPing(simTime()); // if node already in the list, update its lastPing and nodePrio fields if ((iter = bootstrapList.find(node)) != bootstrapList.end()) { iter->second->setLastPing(node.getLastPing()); iter->second->setNodePrio(node.getNodePrio()); return true; } bootstrapList.insert(NodePair(node, &node)); locateBootstrapNode(node); return false; }
void BootstrapList::locateBootstrapNode | ( | const NodeHandle & | node | ) |
Determine locality of a bootstrap node.
node | the newly discovered bootstrap node |
Definition at line 268 of file BootstrapList.cc.
Referenced by insertBootstrapCandidate().
{ Enter_Method_Silent(); if ((overlay->getState() == BaseOverlay::READY) && (!node.isUnspecified()) && mergeOverlayPartitions) { LookupCall* call = new LookupCall(); call->setBitLength(0); call->setKey(node.getKey()); call->setNumSiblings(overlay->getMaxNumSiblings()); sendInternalRpcCall(OVERLAY_COMP, call); } return; }
void BootstrapList::pingResponse | ( | PingResponse * | pingResponse, | |
cPolymorphic * | context, | |||
int | rpcId, | |||
simtime_t | rtt | |||
) | [protected, virtual] |
Definition at line 202 of file BootstrapList.cc.
{ NodeHandle &srcNode = pingResponse->getSrcNode(); BootstrapNodeSet::iterator iter; EV << "[BootstrapList::pingResponse() @ " << overlay->getThisNode().getIp() << " (" << overlay->getThisNode().getKey() << ")]\n" << " Ping response from node " << srcNode << " with rtt " << rtt << endl; // update the lastPing field of the source node if (!srcNode.isUnspecified()) if ((iter = bootstrapList.find(srcNode)) != bootstrapList.end()) iter->second->setLastPing(simTime()); return; }
void BootstrapList::pingTimeout | ( | PingCall * | pingCall, | |
const TransportAddress & | dest, | |||
cPolymorphic * | context, | |||
int | rpcId | |||
) | [protected, virtual] |
Definition at line 223 of file BootstrapList.cc.
{ EV << "[BootstrapList::pingTimeout() @ " << overlay->getThisNode().getIp() << " (" << overlay->getThisNode().getKey() << ")]\n" << " Ping timeout for node " << dest << endl; // destination does not answer, remove it from the list removeBootstrapCandidate(dest); }
void BootstrapList::registerBootstrapNode | ( | const NodeHandle & | node | ) |
Definition at line 364 of file BootstrapList.cc.
Referenced by BaseOverlay::setOverlayReady().
{ globalNodeList->registerPeer(node); // at this point, we consider this node as booted and therefore have to // announce the boot service for it via zeroconfConnector if (zeroconfConnector) { zeroconfConnector->announceService(node); } }
void BootstrapList::removeBootstrapCandidate | ( | const TransportAddress & | addr | ) |
Remove an unavailable bootstrap candidate from the bootstraplist.
addr | the address of the bootstrap candidate |
Definition at line 335 of file BootstrapList.cc.
Referenced by pingTimeout().
{ BootstrapNodeSet::iterator iter; BootstrapNodeHandle* bootstrapNode; if (!addr.isUnspecified()) { if ((iter = bootstrapList.find(addr)) != bootstrapList.end()) { bootstrapNode = iter->second; bootstrapList.erase(iter); delete bootstrapNode; } } return; }
void BootstrapList::removeBootstrapNode | ( | const NodeHandle & | node | ) |
Definition at line 352 of file BootstrapList.cc.
Referenced by BasePastry::baseChangeState(), oversim::Nice::changeState(), Gia::finishOverlay(), oversim::Chord::finishOverlay(), BasePastry::finishOverlay(), Kademlia::joinOverlay(), and BaseOverlay::setOverlayReady().
{ overlay->globalNodeList->removePeer(node); // at this point, we consider this node not being able to provide the // boot service anymore, therefore we have to revoke // the service via zeroconfConnector if (zeroconfConnector) { zeroconfConnector->revokeService(); } }
BootstrapNodeSet BootstrapList::bootstrapList [private] |
Definition at line 110 of file BootstrapList.h.
Referenced by finishApp(), getBootstrapNode(), handleBootstrapListTimerExpired(), handleLookupResponse(), initializeApp(), insertBootstrapCandidate(), pingResponse(), and removeBootstrapCandidate().
bool BootstrapList::maintainList [private] |
maintain a list of bootstrap candidates and check them periodically
Definition at line 147 of file BootstrapList.h.
Referenced by getBootstrapNode(), and initializeApp().
bool BootstrapList::mergeOverlayPartitions [private] |
if true, detect and merge overlay partitions
Definition at line 146 of file BootstrapList.h.
Referenced by initializeApp(), and locateBootstrapNode().
const int BootstrapList::timerInterval = 10 [static, private] |
the interval of the maintenance timer in seconds
Definition at line 142 of file BootstrapList.h.
Referenced by handleBootstrapListTimerExpired(), handleTimerEvent(), and initializeApp().
cMessage* BootstrapList::timerMsg [private] |
self-message for periodic maintenance
Definition at line 144 of file BootstrapList.h.
Referenced by BootstrapList(), handleTimerEvent(), initializeApp(), and ~BootstrapList().
pointer to the ZeroconfConnector module
Definition at line 145 of file BootstrapList.h.
Referenced by BootstrapList(), finishApp(), getBootstrapNode(), initializeApp(), registerBootstrapNode(), and removeBootstrapNode().