diff --git a/src/kademlia/core/DefaultConfiguration.java b/src/kademlia/core/DefaultConfiguration.java index f9498ed..a2bdf57 100644 --- a/src/kademlia/core/DefaultConfiguration.java +++ b/src/kademlia/core/DefaultConfiguration.java @@ -12,7 +12,7 @@ public class DefaultConfiguration implements KadConfiguration private final static long RESTORE_INTERVAL = 60 * 1000; // Default at 1 hour private final static long RESPONSE_TIMEOUT = 1500; - private final static long OPERATION_TIMEOUT = 30000; + private final static long OPERATION_TIMEOUT = 3000; private final static int CONCURRENCY = 10; private final static int K = 10; private final static int RCSIZE = 3; diff --git a/src/kademlia/operation/ConnectOperation.java b/src/kademlia/operation/ConnectOperation.java index 117b875..f015b4f 100644 --- a/src/kademlia/operation/ConnectOperation.java +++ b/src/kademlia/operation/ConnectOperation.java @@ -72,7 +72,7 @@ public class ConnectOperation implements Operation, Receiver if (error) { /* If we still haven't received any responses by then, do a routing timeout */ - throw new RoutingException("Bootstrap node did not respond: " + bootstrapNode); + throw new RoutingException("ConnectOperation: Bootstrap node did not respond: " + bootstrapNode); } /* Perform lookup for our own ID to get nodes close to us */ diff --git a/src/kademlia/operation/ContentLookupOperation.java b/src/kademlia/operation/ContentLookupOperation.java index 4eac85a..9d8ffb0 100644 --- a/src/kademlia/operation/ContentLookupOperation.java +++ b/src/kademlia/operation/ContentLookupOperation.java @@ -48,7 +48,7 @@ public class ContentLookupOperation implements Operation, Receiver private final ContentLookupMessage lookupMessage; - private boolean error, isRunning; + private boolean error, contentsFound; private final SortedMap nodes; /* Tracks messages in transit and awaiting reply */ @@ -61,7 +61,7 @@ public class ContentLookupOperation implements Operation, Receiver { contentFound = new ArrayList<>(); messagesTransiting = new HashMap<>(); - isRunning = true; + contentsFound = false; } /** @@ -108,10 +108,10 @@ public class ContentLookupOperation implements Operation, Receiver /* If we haven't finished as yet, wait for a maximum of config.operationTimeout() time */ int totalTimeWaited = 0; - int timeInterval = 50; // We re-check every 300 milliseconds + int timeInterval = 100; // We re-check every 300 milliseconds while (totalTimeWaited < this.config.operationTimeout()) { - if (!this.askNodesorFinish()) + if (!this.askNodesorFinish() && !contentsFound) { wait(timeInterval); totalTimeWaited += timeInterval; @@ -124,7 +124,7 @@ public class ContentLookupOperation implements Operation, Receiver if (error) { /* If we still haven't received any responses by then, do a routing timeout */ - throw new RoutingException("Lookup Timeout."); + throw new RoutingException("ContentLookupOperation: Lookup Timeout."); } /** @@ -254,7 +254,7 @@ public class ContentLookupOperation implements Operation, Receiver @Override public synchronized void receive(Message incoming, int comm) throws IOException, RoutingException { - if (!this.isRunning) + if (this.contentsFound) { return; } @@ -278,7 +278,8 @@ public class ContentLookupOperation implements Operation, Receiver { /* We've got all the content required, let's stop the loopup operation */ System.out.println("We good"); - this.isRunning = false; + this.error = false; + this.contentsFound = true; } } else diff --git a/src/kademlia/operation/NodeLookupOperation.java b/src/kademlia/operation/NodeLookupOperation.java index 96bbdc4..fcd89d9 100644 --- a/src/kademlia/operation/NodeLookupOperation.java +++ b/src/kademlia/operation/NodeLookupOperation.java @@ -7,7 +7,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; -import kademlia.core.DefaultConfiguration; import kademlia.core.KadConfiguration; import kademlia.core.KadServer; import kademlia.exceptions.RoutingException;