mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-11-22 02:02:21 +00:00
Configuration
- Added Information to specify whether we're in a testing environment or a production environment -- we can use this information to put in network latency, etc Statistician - Adding counting the number of sendData and receiveData operations KademliaNode - Removed the counting of contentLookup if we're getting the content from local storage
This commit is contained in:
parent
70bf6044b3
commit
e771c8fd44
@ -324,16 +324,14 @@ public class KademliaNode
|
|||||||
*/
|
*/
|
||||||
public StorageEntry get(GetParameter param) throws NoSuchElementException, IOException, ContentNotFoundException
|
public StorageEntry get(GetParameter param) throws NoSuchElementException, IOException, ContentNotFoundException
|
||||||
{
|
{
|
||||||
long startTime = System.nanoTime();
|
|
||||||
if (this.dht.contains(param))
|
if (this.dht.contains(param))
|
||||||
{
|
{
|
||||||
/* If the content exist in our own DHT, then return it. */
|
/* If the content exist in our own DHT, then return it. */
|
||||||
long endTime = System.nanoTime();
|
|
||||||
this.statistician.addContentLookup(endTime - startTime, 0);
|
|
||||||
return this.dht.get(param);
|
return this.dht.get(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Seems like it doesn't exist in our DHT, get it from other Nodes */
|
/* Seems like it doesn't exist in our DHT, get it from other Nodes */
|
||||||
|
long startTime = System.nanoTime();
|
||||||
ContentLookupOperation clo = new ContentLookupOperation(server, this, param, this.config);
|
ContentLookupOperation clo = new ContentLookupOperation(server, this, param, this.config);
|
||||||
clo.execute();
|
clo.execute();
|
||||||
long endTime = System.nanoTime();
|
long endTime = System.nanoTime();
|
||||||
|
@ -15,6 +15,7 @@ public class Statistician
|
|||||||
|
|
||||||
/* How much data was sent and received by the server over the network */
|
/* How much data was sent and received by the server over the network */
|
||||||
private long totalDataSent, totalDataReceived;
|
private long totalDataSent, totalDataReceived;
|
||||||
|
private long numDataSent, numDataReceived;
|
||||||
|
|
||||||
/* Bootstrap timings */
|
/* Bootstrap timings */
|
||||||
private long bootstrapTime;
|
private long bootstrapTime;
|
||||||
@ -42,6 +43,7 @@ public class Statistician
|
|||||||
public void sentData(long size)
|
public void sentData(long size)
|
||||||
{
|
{
|
||||||
this.totalDataSent += size;
|
this.totalDataSent += size;
|
||||||
|
this.numDataSent++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,6 +62,7 @@ public class Statistician
|
|||||||
public void receivedData(long size)
|
public void receivedData(long size)
|
||||||
{
|
{
|
||||||
this.totalDataReceived += size;
|
this.totalDataReceived += size;
|
||||||
|
this.numDataReceived++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -136,12 +139,18 @@ public class Statistician
|
|||||||
sb.append("; ");
|
sb.append("; ");
|
||||||
|
|
||||||
sb.append("Data Sent: ");
|
sb.append("Data Sent: ");
|
||||||
|
sb.append("(");
|
||||||
|
sb.append(this.numDataSent);
|
||||||
|
sb.append(") ");
|
||||||
sb.append(this.getTotalDataSent());
|
sb.append(this.getTotalDataSent());
|
||||||
sb.append("; ");
|
sb.append(" bytes; ");
|
||||||
|
|
||||||
sb.append("Data Received: ");
|
sb.append("Data Received: ");
|
||||||
|
sb.append("(");
|
||||||
|
sb.append(this.numDataReceived);
|
||||||
|
sb.append(") ");
|
||||||
sb.append(this.getTotalDataReceived());
|
sb.append(this.getTotalDataReceived());
|
||||||
sb.append("; ");
|
sb.append(" bytes; ");
|
||||||
|
|
||||||
sb.append("Num Content Lookups: ");
|
sb.append("Num Content Lookups: ");
|
||||||
sb.append(this.numContentLookups());
|
sb.append(this.numContentLookups());
|
||||||
|
@ -18,6 +18,8 @@ public class DefaultConfiguration implements KadConfiguration
|
|||||||
private final static int RCSIZE = 3;
|
private final static int RCSIZE = 3;
|
||||||
private final static int STALE = 1;
|
private final static int STALE = 1;
|
||||||
private final static String LOCAL_FOLDER = "kademlia";
|
private final static String LOCAL_FOLDER = "kademlia";
|
||||||
|
|
||||||
|
private final static boolean IS_TESTING = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor to support Gson Serialization
|
* Default constructor to support Gson Serialization
|
||||||
@ -90,4 +92,10 @@ public class DefaultConfiguration implements KadConfiguration
|
|||||||
/* Return the path */
|
/* Return the path */
|
||||||
return ownerFolder.toString();
|
return ownerFolder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTesting()
|
||||||
|
{
|
||||||
|
return IS_TESTING;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ package kademlia.core;
|
|||||||
*/
|
*/
|
||||||
public interface KadConfiguration
|
public interface KadConfiguration
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Interval in milliseconds between execution of RestoreOperations.
|
* @return Interval in milliseconds between execution of RestoreOperations.
|
||||||
*/
|
*/
|
||||||
@ -48,11 +48,16 @@ public interface KadConfiguration
|
|||||||
public int stale();
|
public int stale();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the folder in which this node data is to be stored
|
* Creates the folder in which this node data is to be stored.
|
||||||
*
|
*
|
||||||
* @param ownerId
|
* @param ownerId
|
||||||
*
|
*
|
||||||
* @return The folder path
|
* @return The folder path
|
||||||
*/
|
*/
|
||||||
public String getNodeDataFolder(String ownerId);
|
public String getNodeDataFolder(String ownerId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Whether we're in a testing or production system.
|
||||||
|
*/
|
||||||
|
public boolean isTesting();
|
||||||
}
|
}
|
||||||
|
@ -208,6 +208,14 @@ public class KadServer
|
|||||||
/* Lets inform the statistician that we've received some data */
|
/* Lets inform the statistician that we've received some data */
|
||||||
this.statistician.receivedData(packet.getLength());
|
this.statistician.receivedData(packet.getLength());
|
||||||
|
|
||||||
|
if (this.config.isTesting())
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Simulating network latency
|
||||||
|
* We pause for 1 millisecond/100 bytes
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
/* We've received a packet, now handle it */
|
/* We've received a packet, now handle it */
|
||||||
try (ByteArrayInputStream bin = new ByteArrayInputStream(packet.getData(), packet.getOffset(), packet.getLength());
|
try (ByteArrayInputStream bin = new ByteArrayInputStream(packet.getData(), packet.getOffset(), packet.getLength());
|
||||||
DataInputStream din = new DataInputStream(bin);)
|
DataInputStream din = new DataInputStream(bin);)
|
||||||
|
Loading…
Reference in New Issue
Block a user