62 zeroconfConnector = NULL;
69 cancelAndDelete(timerMsg);
79 mergeOverlayPartitions = par(
"mergeOverlayPartitions");
80 maintainList = par(
"maintainList");
82 if (getParentModule()->getParentModule()->getSubmodule(
"zeroconfConnector", 0)) {
84 getParentModule()->getSubmodule(
"zeroconfConnector", 0));
85 if (!zeroconfConnector->isEnabled()) {
86 zeroconfConnector = NULL;
91 if (zeroconfConnector) {
92 ifstream nodeListFile(
"nodelist.dat", ios::in);
94 EV <<
"[BootstrapList::initializeApp() @ " << overlay->getThisNode().getIp()
95 <<
" (" << overlay->getThisNode().getKey() <<
")]\n"
96 <<
" nodelist.dat not found"
104 while (nodeListFile >> address >> port >> key) {
106 IPvXAddress(address), port,
109 insertBootstrapCandidate(*node);
111 nodeListFile.close();
114 if (bootstrapList.size()) sendReadyMessage();
123 timerMsg =
new cMessage(
"BootstrapListTimer");
124 scheduleAt(simTime() + timerInterval, timerMsg);
131 if (msg == timerMsg) {
132 handleBootstrapListTimerExpired();
133 scheduleAt(simTime() + timerInterval, msg);
135 throw cRuntimeError(
"BootstrapList::handleTimerEvent(): "
136 "Received unknown self-message!");
142 simtime_t current = simTime();
144 BootstrapNodeSet::iterator iter;
146 for (iter = bootstrapList.begin(); iter != bootstrapList.end(); iter++) {
148 if (timerInterval <= SIMTIME_DBL(current - node->
getLastPing())) {
156 cPolymorphic* context,
157 int rpcId, simtime_t rtt)
161 handleLookupResponse(_LookupResponse);
162 EV <<
"[BootstrapList::handleRpcResponse() @ "
163 << overlay->getThisNode().getIp()
164 <<
" (" << overlay->getThisNode().getKey().toString(16) <<
")]\n"
165 <<
" Lookup RPC Response received: id=" << rpcId <<
"\n"
166 <<
" msg=" << *_LookupResponse <<
" rtt=" << rtt
174 EV <<
"[BootstrapList::handleLookupResponse() @ "
175 << overlay->getThisNode().getIp()
176 <<
" (" << overlay->getThisNode().getKey().toString(16) <<
")]\n"
177 <<
" Lookup response for key " << msg->
getKey()<<
" : ";
183 <<
"belongs to a local node." << endl;
188 EV <<
"New partition discovered, going to join." << endl;
189 BootstrapNodeSet::iterator iter;
190 for (iter = bootstrapList.begin(); iter != bootstrapList.end(); iter++) {
191 if (iter->second->getKey() == msg->
getKey())
192 overlay->joinForeignPartition(*iter->second);
196 EV <<
"failed" << endl;
204 cPolymorphic* context,
205 int rpcId, simtime_t rtt)
208 BootstrapNodeSet::iterator iter;
210 EV <<
"[BootstrapList::pingResponse() @ " << overlay->getThisNode().
getIp()
211 <<
" (" << overlay->getThisNode().getKey() <<
")]\n"
212 <<
" Ping response from node " << srcNode
213 <<
" with rtt " << rtt << endl;
217 if ((iter = bootstrapList.find(srcNode)) != bootstrapList.end())
218 iter->second->setLastPing(simTime());
226 cPolymorphic* context,
229 EV <<
"[BootstrapList::pingTimeout() @ " << overlay->getThisNode().getIp()
230 <<
" (" << overlay->getThisNode().getKey() <<
")]\n"
231 <<
" Ping timeout for node " << dest << endl;
233 removeBootstrapCandidate(dest);
247 return overlay->globalNodeList->getRandomNode(overlayId, -1,
true,
255 if (!bootstrapList.empty()) {
256 i = intrand(bootstrapList.size());
257 BootstrapNodeSet::iterator iter = bootstrapList.begin();
267 if (!zeroconfConnector)
268 bootstrapNode = &overlay->globalNodeList->
269 getBootstrapNode(overlayId, overlay->getThisNode());
271 return *bootstrapNode;
278 Enter_Method_Silent();
281 && mergeOverlayPartitions) {
283 call->setBitLength(0);
296 Enter_Method_Silent();
298 BootstrapNodeSet::iterator iter;
302 if ((iter = bootstrapList.find(node)) != bootstrapList.end()) {
304 iter->second->setNodePrio(prio);
311 bootstrapList.insert(
NodePair(*bootstrapNode, bootstrapNode));
314 locateBootstrapNode(node);
322 Enter_Method_Silent();
324 BootstrapNodeSet::iterator iter;
329 if ((iter = bootstrapList.find(node)) != bootstrapList.end()) {
336 bootstrapList.insert(
NodePair(node, &node));
337 locateBootstrapNode(node);
345 BootstrapNodeSet::iterator iter;
349 if ((iter = bootstrapList.find(addr)) != bootstrapList.end()) {
350 bootstrapNode = iter->second;
351 bootstrapList.erase(iter);
352 delete bootstrapNode;
363 overlay->globalNodeList->removePeer(node, overlayId);
367 if (zeroconfConnector) {
368 zeroconfConnector->revokeService();
376 globalNodeList->registerPeer(node, overlayId);
380 if (zeroconfConnector) {
381 zeroconfConnector->announceService(node);
390 if (zeroconfConnector) {
391 ofstream nodeListFile(
"nodelist.dat", ios::out|ios::trunc);
393 std::cerr <<
"nodelist.dat could not be opened" << endl;
395 for (BootstrapNodeSet::iterator iter = bootstrapList.begin();
396 iter != bootstrapList.end(); iter++) {
397 nodeListFile << iter->second->getIp().str() <<
' '
398 << iter->second->getPort() <<
' '
399 << iter->second->getKey().toString(16) <<
'\n';
401 nodeListFile.close();
406 for (BootstrapNodeSet::iterator iter = bootstrapList.begin();
407 iter != bootstrapList.end(); iter++) {
411 bootstrapList.clear();