Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Bugfix in kademlia example
authorSamuel Lepetit <samuel.lepetit@inria.fr>
Thu, 28 Jun 2012 08:28:03 +0000 (10:28 +0200)
committerSamuel Lepetit <samuel.lepetit@inria.fr>
Thu, 28 Jun 2012 08:28:03 +0000 (10:28 +0200)
examples/kademlia/Node.java
examples/kademlia/RoutingTable.java

index 7312d26..cdcc71a 100644 (file)
@@ -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.
         */
index a25acdf..2457354 100644 (file)
@@ -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);