int nodesAdded = 0;
boolean destinationFound = false;
int steps = 0;
- double timeBeginReceive;
+ double timeBeginReceive = Msg.getClock();
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);
steps++;
do {
try {
- timeBeginReceive = Msg.getClock();
if (comm == null) {
comm = Task.irecv(Integer.toString(id));
}
- comm.waitCompletion(10);
if (!comm.test()) {
waitFor(1);
}
}
else {
handleTask(task);
- timeout += Msg.getClock() - timeBeginReceive;
+ timeBeginReceive = Msg.getClock();
+ timeout += Msg.getClock() - timeBeginReceive;
}
}
else {
handleTask(task);
+ timeBeginReceive = Msg.getClock();
timeout += Msg.getClock() - timeBeginReceive;
}
comm = null;
} while (Msg.getClock() < timeout && !destinationFound);
}
/**
- * Sends a "FIND_NODE" request (task) to the node we know.
+ * Sends a "FIND_NODE" request (task) to a node we know.
* @brief id Id of the node we are querying
* @brief destination id of the node we are trying to find.
*/
bucket.addToAnswer(answer,destinationId);
for (int i = 1; answer.size() < Common.BUCKET_SIZE &&
- (bucket.getId() - i) >= 0 &&
- (bucket.getId() + i) <= Common.IDENTIFIER_SIZE; i++) {
+ ((bucket.getId() - i) >= 0 ||
+ (bucket.getId() + i) <= Common.IDENTIFIER_SIZE); i++) {
//Check the previous buckets
if (bucket.getId() - i >= 0) {
Bucket bucketP = this.buckets.get(bucket.getId() - i);