mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-11-22 02:02:21 +00:00
Improve response check time
When doing a NodeLookup, Content Lookup or Connect operation, after sending the message, we used to wait(operation_timeout) time before checking for a result. Now what I'm doing is waiting for 100 ms and check for a result every 100ms; I keep a count of total time waited, and only when the total time > operation_timeout do we make a timeout. So now we can handle the response if it comes in before Operation_timeout time is finished
This commit is contained in:
parent
eaeffeb0ba
commit
4888bf4dd4
@ -10,11 +10,11 @@ import java.io.File;
|
||||
public class DefaultConfiguration implements KadConfiguration
|
||||
{
|
||||
|
||||
private final static long RESTORE_INTERVAL = 60 * 1000; // Default at 1 hour
|
||||
private final static long RESTORE_INTERVAL = 5 * 1000; // Default at 1 hour
|
||||
private final static long RESPONSE_TIMEOUT = 1500;
|
||||
private final static long OPERATION_TIMEOUT = 3000;
|
||||
private final static long OPERATION_TIMEOUT = 30000;
|
||||
private final static int CONCURRENCY = 10;
|
||||
private final static int K = 2;
|
||||
private final static int K = 10;
|
||||
private final static int RCSIZE = 3;
|
||||
private final static int STALE = 1;
|
||||
private final static String LOCAL_FOLDER = "kademlia";
|
||||
|
@ -54,12 +54,24 @@ public class ConnectOperation implements Operation, Receiver
|
||||
/* Send a connect message to the bootstrap node */
|
||||
server.sendMessage(this.bootstrapNode, m, this);
|
||||
|
||||
/* Wait for a while */
|
||||
wait(config.operationTimeout());
|
||||
|
||||
/* If we haven't finished as yet, wait for a maximum of config.operationTimeout() time */
|
||||
int totalTimeWaited = 0;
|
||||
int timeInterval = 100; // We re-check every 300 milliseconds
|
||||
while (totalTimeWaited < this.config.operationTimeout())
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
/* Means the contact failed */
|
||||
wait(timeInterval);
|
||||
totalTimeWaited += timeInterval;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -106,26 +106,44 @@ public class ContentLookupOperation implements Operation, Receiver
|
||||
|
||||
this.addNodes(this.localNode.getRoutingTable().getAllNodes());
|
||||
|
||||
/* If we haven't finished as yet, wait for a maximum of config.operationTimeout() time */
|
||||
int totalTimeWaited = 0;
|
||||
int timeInterval = 100; // We re-check every 300 milliseconds
|
||||
while (totalTimeWaited < this.config.operationTimeout())
|
||||
{
|
||||
if (!this.askNodesorFinish())
|
||||
{
|
||||
/* If we haven't finished as yet, wait a while */
|
||||
/**
|
||||
* @todo Get rid of this wait here!
|
||||
* We should run this until there are no nodes left to ask from the K closest nodes
|
||||
* and only pause for short intervals in between
|
||||
*
|
||||
* @todo Do the same for the NodeLookupOperation
|
||||
*/
|
||||
wait(this.config.operationTimeout());
|
||||
|
||||
/* If we still haven't received any responses by then, do a routing timeout */
|
||||
wait(timeInterval);
|
||||
totalTimeWaited += timeInterval;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (error)
|
||||
{
|
||||
/* Lets not throw any exception */
|
||||
/* If we still haven't received any responses by then, do a routing timeout */
|
||||
throw new RoutingException("Lookup Timeout.");
|
||||
}
|
||||
|
||||
//throw new RoutingException("Content Lookup Operation Timeout.");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @deprecated - replaced by the above code
|
||||
* We just keep this code in case any problems are encountered later
|
||||
*/
|
||||
// if (!this.askNodesorFinish())
|
||||
// {
|
||||
// /* If we haven't finished as yet, wait a while */
|
||||
// wait(this.config.operationTimeout());
|
||||
//
|
||||
// /* If we still haven't received any responses by then, do a routing timeout */
|
||||
// if (error)
|
||||
// {
|
||||
// /* Lets not throw any exception */
|
||||
//
|
||||
// //throw new RoutingException("Content Lookup Operation Timeout.");
|
||||
// }
|
||||
// }
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
|
@ -97,17 +97,42 @@ public class NodeLookupOperation implements Operation, Receiver
|
||||
|
||||
this.addNodes(this.localNode.getRoutingTable().getAllNodes());
|
||||
|
||||
/* If we haven't finished as yet, wait for a maximum of config.operationTimeout() time */
|
||||
int totalTimeWaited = 0;
|
||||
int timeInterval = 100; // We re-check every 300 milliseconds
|
||||
while (totalTimeWaited < this.config.operationTimeout())
|
||||
{
|
||||
if (!this.askNodesorFinish())
|
||||
{
|
||||
/* If we haven't finished as yet, wait a while */
|
||||
wait(this.config.operationTimeout());
|
||||
|
||||
/* If we still haven't received any responses by then, do a routing timeout */
|
||||
wait(timeInterval);
|
||||
totalTimeWaited += timeInterval;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (error)
|
||||
{
|
||||
/* If we still haven't received any responses by then, do a routing timeout */
|
||||
throw new RoutingException("Lookup Timeout.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated - replaced by the above code
|
||||
* We just keep this code in case any problems are encountered later
|
||||
*/
|
||||
// if (!this.askNodesorFinish())
|
||||
// {
|
||||
// /* If we haven't finished as yet, wait for a maximum of OPERATION_TIMEOUT time */
|
||||
// wait(this.config.operationTimeout());
|
||||
//
|
||||
// /* If we still haven't received any responses by then, do a routing timeout */
|
||||
// if (error)
|
||||
// {
|
||||
// throw new RoutingException("Lookup Timeout.");
|
||||
// }
|
||||
// }
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user