mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-12-23 08:11:47 +00:00
ContentLookupOperation
CLO was timing out even if it had found the specified amount of content needed. Fixed that by exiting after the specified # of content required has been found
This commit is contained in:
parent
c31e0002e2
commit
8e6052de23
@ -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;
|
||||
|
@ -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 */
|
||||
|
@ -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<Node, Byte> 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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user