2014-05-05 12:33:57 +00:00
|
|
|
package kademlia;
|
|
|
|
|
|
|
|
/**
|
2014-05-06 03:43:16 +00:00
|
|
|
* Class that keeps statistics for this Kademlia instance.
|
|
|
|
*
|
|
|
|
* These statistics are temporary and will be lost when Kad is shut down.
|
2014-05-05 12:33:57 +00:00
|
|
|
*
|
|
|
|
* @author Joshua Kissoon
|
|
|
|
* @since 20140505
|
|
|
|
*/
|
2014-05-06 03:51:34 +00:00
|
|
|
public class Statistician
|
2014-05-05 12:33:57 +00:00
|
|
|
{
|
|
|
|
|
2014-05-06 03:43:16 +00:00
|
|
|
/* How much data was sent and received by the server over the network */
|
|
|
|
private long totalDataSent, totalDataReceived;
|
|
|
|
|
2014-05-06 19:11:49 +00:00
|
|
|
/* Bootstrap timings */
|
|
|
|
private long bootstrapTime;
|
|
|
|
|
2014-05-07 03:56:29 +00:00
|
|
|
/* Content lookup operation timing & route length */
|
2014-05-06 19:11:49 +00:00
|
|
|
private int numContentLookups;
|
|
|
|
private long totalContentLookupTime;
|
2014-05-07 03:56:29 +00:00
|
|
|
private long totalRouteLength;
|
2014-05-06 19:11:49 +00:00
|
|
|
|
2014-05-06 03:43:16 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
this.totalDataSent = 0;
|
|
|
|
this.totalDataReceived = 0;
|
2014-05-06 19:11:49 +00:00
|
|
|
this.bootstrapTime = 0;
|
|
|
|
this.numContentLookups = 0;
|
|
|
|
this.totalContentLookupTime = 0;
|
2014-05-07 03:56:29 +00:00
|
|
|
this.totalRouteLength = 0;
|
2014-05-06 03:43:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to indicate some data is sent
|
|
|
|
*
|
|
|
|
* @param size The size of the data sent
|
|
|
|
*/
|
|
|
|
public void sentData(long size)
|
|
|
|
{
|
|
|
|
this.totalDataSent += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return The total data sent
|
|
|
|
*/
|
|
|
|
public long getTotalDataSent()
|
|
|
|
{
|
|
|
|
return this.totalDataSent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to indicate some data was received
|
|
|
|
*
|
|
|
|
* @param size The size of the data received
|
|
|
|
*/
|
|
|
|
public void receivedData(long size)
|
|
|
|
{
|
|
|
|
this.totalDataReceived += size;
|
|
|
|
}
|
|
|
|
|
2014-05-05 12:33:57 +00:00
|
|
|
/**
|
2014-05-06 03:43:16 +00:00
|
|
|
* @return The total data received
|
2014-05-05 12:33:57 +00:00
|
|
|
*/
|
2014-05-06 03:43:16 +00:00
|
|
|
public long getTotalDataReceived()
|
|
|
|
{
|
|
|
|
return this.totalDataReceived;
|
|
|
|
}
|
2014-05-06 19:11:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the bootstrap time for this Kademlia Node
|
|
|
|
*
|
2014-05-06 19:24:55 +00:00
|
|
|
* @param time The bootstrap time in nanoseconds
|
2014-05-06 19:11:49 +00:00
|
|
|
*/
|
|
|
|
public void setBootstrapTime(long time)
|
|
|
|
{
|
|
|
|
this.bootstrapTime = time;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getBootstrapTime()
|
|
|
|
{
|
|
|
|
return this.bootstrapTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the timing for a new content lookup operation that took place
|
|
|
|
*
|
2014-05-07 03:56:29 +00:00
|
|
|
* @param time The time the content lookup took in nanoseconds
|
|
|
|
* @param routeLength The length of the route it took to get the content
|
2014-05-06 19:11:49 +00:00
|
|
|
*/
|
2014-05-07 03:56:29 +00:00
|
|
|
public void addContentLookup(long time, int routeLength)
|
2014-05-06 19:11:49 +00:00
|
|
|
{
|
|
|
|
this.numContentLookups++;
|
|
|
|
this.totalContentLookupTime += time;
|
2014-05-07 03:56:29 +00:00
|
|
|
this.totalRouteLength += routeLength;
|
2014-05-06 19:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int numContentLookups()
|
|
|
|
{
|
|
|
|
return this.numContentLookups;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long totalContentLookupTime()
|
|
|
|
{
|
|
|
|
return this.totalContentLookupTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute the average time a content lookup took
|
|
|
|
*
|
|
|
|
* @return The average time
|
|
|
|
*/
|
|
|
|
public long averageContentLookupTime()
|
|
|
|
{
|
|
|
|
return this.totalContentLookupTime / this.numContentLookups;
|
|
|
|
}
|
2014-05-05 12:33:57 +00:00
|
|
|
}
|