From 57f5d434ecd7f3e3d6573cbd2a33257c5b35082a Mon Sep 17 00:00:00 2001 From: Samuel Lepetit Date: Tue, 3 Jul 2012 10:57:27 +0200 Subject: [PATCH] Cleanup in Kademlia example --- examples/kademlia/Answer.java | 2 +- examples/kademlia/Node.java | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/kademlia/Answer.java b/examples/kademlia/Answer.java index ac142b7993..158231c4d8 100644 --- a/examples/kademlia/Answer.java +++ b/examples/kademlia/Answer.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2010. The SimGrid Team. +/* Copyright (c) 2012. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it diff --git a/examples/kademlia/Node.java b/examples/kademlia/Node.java index 1655a7dbcd..437f7afec8 100644 --- a/examples/kademlia/Node.java +++ b/examples/kademlia/Node.java @@ -178,7 +178,7 @@ public class Node extends Process { * 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; @@ -186,12 +186,11 @@ public class Node extends Process { 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++; @@ -215,12 +214,15 @@ public class Node extends Process { 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(); } @@ -244,11 +246,11 @@ public class Node extends Process { 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++; @@ -257,7 +259,7 @@ public class Node extends Process { 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) { @@ -346,6 +348,4 @@ public class Node extends Process { PingAnswerTask taskToSend = new PingAnswerTask(this.id); taskToSend.dsend(Integer.toString(task.getSenderId())); } - - } -- 2.20.1