2014-03-29 09:07:01 +00:00
|
|
|
package kademlia.core;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A set of Kademlia configuration parameters. Default values are
|
|
|
|
* supplied and can be changed by the application as necessary.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class DefaultConfiguration implements KadConfiguration
|
|
|
|
{
|
|
|
|
|
2014-04-26 15:56:02 +00:00
|
|
|
private final static long RESTORE_INTERVAL = 1000 * 1000; // Default at 1 hour
|
2014-03-29 09:07:01 +00:00
|
|
|
private final static long RESPONSE_TIMEOUT = 1500;
|
2014-04-13 13:45:24 +00:00
|
|
|
private final static long OPERATION_TIMEOUT = 3000;
|
2014-03-29 09:07:01 +00:00
|
|
|
private final static int CONCURRENCY = 10;
|
2014-04-28 09:55:07 +00:00
|
|
|
private final static int K = 3;
|
2014-03-29 09:07:01 +00:00
|
|
|
private final static int RCSIZE = 3;
|
|
|
|
private final static int STALE = 1;
|
|
|
|
private final static String LOCAL_FOLDER = "kademlia";
|
|
|
|
|
2014-03-31 17:20:57 +00:00
|
|
|
/**
|
|
|
|
* Default constructor to support Gson Serialization
|
|
|
|
*/
|
|
|
|
public DefaultConfiguration()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-03-29 09:07:01 +00:00
|
|
|
@Override
|
|
|
|
public long restoreInterval()
|
|
|
|
{
|
|
|
|
return RESTORE_INTERVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long responseTimeout()
|
|
|
|
{
|
|
|
|
return RESPONSE_TIMEOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long operationTimeout()
|
|
|
|
{
|
|
|
|
return OPERATION_TIMEOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int maxConcurrentMessagesTransiting()
|
|
|
|
{
|
|
|
|
return CONCURRENCY;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int k()
|
|
|
|
{
|
|
|
|
return K;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int replacementCacheSize()
|
|
|
|
{
|
|
|
|
return RCSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int stale()
|
|
|
|
{
|
|
|
|
return STALE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getNodeDataFolder(String ownerId)
|
|
|
|
{
|
|
|
|
/* Setup the main storage folder if it doesn't exist */
|
|
|
|
String path = System.getProperty("user.home") + File.separator + DefaultConfiguration.LOCAL_FOLDER;
|
|
|
|
File folder = new File(path);
|
|
|
|
if (!folder.isDirectory())
|
|
|
|
{
|
|
|
|
folder.mkdir();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup subfolder for this owner if it doesn't exist */
|
|
|
|
File ownerFolder = new File(folder + File.separator + ownerId);
|
|
|
|
if (!ownerFolder.isDirectory())
|
|
|
|
{
|
|
|
|
ownerFolder.mkdir();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the path */
|
|
|
|
return ownerFolder.toString();
|
|
|
|
}
|
|
|
|
}
|