diff --git a/src/kademlia/KademliaNode.java b/src/kademlia/KademliaNode.java index 143ed6c..c94aef0 100644 --- a/src/kademlia/KademliaNode.java +++ b/src/kademlia/KademliaNode.java @@ -329,7 +329,7 @@ public class KademliaNode { /* If the content exist in our own DHT, then return it. */ long endTime = System.nanoTime(); - this.statistician.addContentLookupTime(endTime - startTime); + this.statistician.addContentLookup(endTime - startTime, 0); return this.dht.get(param); } @@ -337,7 +337,7 @@ public class KademliaNode ContentLookupOperation clo = new ContentLookupOperation(server, this, param, this.config); clo.execute(); long endTime = System.nanoTime(); - this.statistician.addContentLookupTime(endTime - startTime); + this.statistician.addContentLookup(endTime - startTime, clo.routeLength()); return clo.getContentFound(); } diff --git a/src/kademlia/Statistician.java b/src/kademlia/Statistician.java index ab6fd29..2875d7b 100644 --- a/src/kademlia/Statistician.java +++ b/src/kademlia/Statistician.java @@ -17,9 +17,10 @@ public class Statistician /* Bootstrap timings */ private long bootstrapTime; - /* Content lookup operation timing */ + /* Content lookup operation timing & route length */ private int numContentLookups; private long totalContentLookupTime; + private long totalRouteLength; { @@ -28,6 +29,7 @@ public class Statistician this.bootstrapTime = 0; this.numContentLookups = 0; this.totalContentLookupTime = 0; + this.totalRouteLength = 0; } /** @@ -84,12 +86,14 @@ public class Statistician /** * Add the timing for a new content lookup operation that took place * - * @param time The time the content lookup took in nanoseconds + * @param time The time the content lookup took in nanoseconds + * @param routeLength The length of the route it took to get the content */ - public void addContentLookupTime(long time) + public void addContentLookup(long time, int routeLength) { this.numContentLookups++; this.totalContentLookupTime += time; + this.totalRouteLength += routeLength; } public int numContentLookups() diff --git a/src/kademlia/operation/ContentLookupOperation.java b/src/kademlia/operation/ContentLookupOperation.java index 2fd14b5..fcbe2a0 100644 --- a/src/kademlia/operation/ContentLookupOperation.java +++ b/src/kademlia/operation/ContentLookupOperation.java @@ -56,10 +56,14 @@ public class ContentLookupOperation implements Operation, Receiver /* Used to sort nodes */ private final Comparator comparator; + /* Statistical information */ + private int routeLength; // Length of the route to find this content + { messagesTransiting = new HashMap<>(); isContentFound = false; + routeLength = 1; } /** @@ -250,6 +254,9 @@ public class ContentLookupOperation implements Operation, Receiver } else { + /* Our hop length is increased */ + this.routeLength++; + /* The reply received is a NodeReplyMessage with nodes closest to the content needed */ NodeReplyMessage msg = (NodeReplyMessage) incoming; @@ -311,4 +318,12 @@ public class ContentLookupOperation implements Operation, Receiver throw new ContentNotFoundException("No Value was found for the given key."); } } + + /** + * @return How many hops it took in order to get to the content. + */ + public int routeLength() + { + return this.routeLength; + } }