* Send a request to find a node in the node's routing table.
*/
public boolean findNode(int destination, boolean counts) {
- int queries, answers, totalQueries = 0, totalAnswers = 0;
+ int queries, answers;
int nodesAdded = 0;
boolean destinationFound = false;
int steps = 0;
double timeout, globalTimeout = Msg.getClock() + Common.FIND_NODE_GLOBAL_TIMEOUT;
//Build a list of the closest nodes we already know.
Answer nodeList = table.findClosest(destination);
- Msg.debug("Doing a FIND_NODE on " + destination);
+ Msg.verb("Doing a FIND_NODE on " + destination);
do {
timeBeginReceive = Msg.getClock();
answers = 0;
queries = this.sendFindNodeToBest(nodeList);
- totalQueries += queries;
nodesAdded = 0;
timeout = Msg.getClock() + Common.FIND_NODE_TIMEOUT;
steps++;
table.update(c.getId());
}
answers++;
- totalAnswers++;
nodesAdded = nodeList.merge(answerTask.getAnswer());
}
+ /* If it's not our answer, we answer to the node that
+ * has queried us anyway
+ */
else {
handleTask(task);
+ //Update the timeout if it's not our answer.
timeout += Msg.getClock() - timeBeginReceive;
timeBeginReceive = Msg.getClock();
}
if (counts) {
findNodeSuccedded++;
}
- Msg.debug("Find node on " + destination + " succedded with " + totalQueries + " queries and " + totalAnswers + " answers");
+ Msg.debug("Find node on " + destination + " succedded");
}
else {
Msg.debug("Find node on " + destination + " failed");
- Msg.debug("Queried " + queries + " nodes to find " + destination + ", got " + totalAnswers + " answers");
+ Msg.debug("Queried " + queries + " nodes to find " + destination);
Msg.debug(nodeList.toString());
if (counts) {
findNodeFailed++;
return destinationFound;
}
/**
- * Sends a "PING" reque ast to a node
+ * Sends a "PING" request to a node
* @param destination Ping destination id.
*/
public void ping(int destination) {
PingAnswerTask taskToSend = new PingAnswerTask(this.id);
taskToSend.dsend(Integer.toString(task.getSenderId()));
}
-
-
}