From: Samuel Lepetit Date: Thu, 28 Jun 2012 08:28:03 +0000 (+0200) Subject: Bugfix in kademlia example X-Git-Tag: v3_9_90~569^2~19^2~31 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/01f4354d59ef70e1b57fb8f50a927b5566c47ce9 Bugfix in kademlia example --- diff --git a/examples/kademlia/Node.java b/examples/kademlia/Node.java index 7312d26951..cdcc71a071 100644 --- a/examples/kademlia/Node.java +++ b/examples/kademlia/Node.java @@ -182,7 +182,7 @@ public class Node extends Process { 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); @@ -196,11 +196,9 @@ public class Node extends Process { steps++; do { try { - timeBeginReceive = Msg.getClock(); if (comm == null) { comm = Task.irecv(Integer.toString(id)); } - comm.waitCompletion(10); if (!comm.test()) { waitFor(1); } @@ -222,11 +220,13 @@ public class Node extends Process { } 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; @@ -289,7 +289,7 @@ public class Node extends Process { } 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. */ diff --git a/examples/kademlia/RoutingTable.java b/examples/kademlia/RoutingTable.java index a25acdfa38..2457354171 100644 --- a/examples/kademlia/RoutingTable.java +++ b/examples/kademlia/RoutingTable.java @@ -95,8 +95,8 @@ public class RoutingTable { 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);