From e771c8fd44b171ab83af8bdab08b92c0c267ae00 Mon Sep 17 00:00:00 2001 From: Joshua Kissoon Date: Wed, 7 May 2014 22:43:15 +0530 Subject: [PATCH] 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 --- src/kademlia/KademliaNode.java | 4 +--- src/kademlia/Statistician.java | 13 +++++++++++-- src/kademlia/core/DefaultConfiguration.java | 8 ++++++++ src/kademlia/core/KadConfiguration.java | 9 +++++++-- src/kademlia/core/KadServer.java | 8 ++++++++ 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/kademlia/KademliaNode.java b/src/kademlia/KademliaNode.java index c94aef0..31ed6cc 100644 --- a/src/kademlia/KademliaNode.java +++ b/src/kademlia/KademliaNode.java @@ -324,16 +324,14 @@ public class KademliaNode */ public StorageEntry get(GetParameter param) throws NoSuchElementException, IOException, ContentNotFoundException { - long startTime = System.nanoTime(); if (this.dht.contains(param)) { /* 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); } /* 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); clo.execute(); long endTime = System.nanoTime(); diff --git a/src/kademlia/Statistician.java b/src/kademlia/Statistician.java index 6f7311a..47ebcb1 100644 --- a/src/kademlia/Statistician.java +++ b/src/kademlia/Statistician.java @@ -15,6 +15,7 @@ public class Statistician /* How much data was sent and received by the server over the network */ private long totalDataSent, totalDataReceived; + private long numDataSent, numDataReceived; /* Bootstrap timings */ private long bootstrapTime; @@ -42,6 +43,7 @@ public class Statistician public void sentData(long size) { this.totalDataSent += size; + this.numDataSent++; } /** @@ -60,6 +62,7 @@ public class Statistician public void receivedData(long size) { this.totalDataReceived += size; + this.numDataReceived++; } /** @@ -136,12 +139,18 @@ public class Statistician sb.append("; "); sb.append("Data Sent: "); + sb.append("("); + sb.append(this.numDataSent); + sb.append(") "); sb.append(this.getTotalDataSent()); - sb.append("; "); + sb.append(" bytes; "); sb.append("Data Received: "); + sb.append("("); + sb.append(this.numDataReceived); + sb.append(") "); sb.append(this.getTotalDataReceived()); - sb.append("; "); + sb.append(" bytes; "); sb.append("Num Content Lookups: "); sb.append(this.numContentLookups()); diff --git a/src/kademlia/core/DefaultConfiguration.java b/src/kademlia/core/DefaultConfiguration.java index 0363388..eba0cdb 100644 --- a/src/kademlia/core/DefaultConfiguration.java +++ b/src/kademlia/core/DefaultConfiguration.java @@ -18,6 +18,8 @@ public class DefaultConfiguration implements KadConfiguration private final static int RCSIZE = 3; private final static int STALE = 1; private final static String LOCAL_FOLDER = "kademlia"; + + private final static boolean IS_TESTING = true; /** * Default constructor to support Gson Serialization @@ -90,4 +92,10 @@ public class DefaultConfiguration implements KadConfiguration /* Return the path */ return ownerFolder.toString(); } + + @Override + public boolean isTesting() + { + return IS_TESTING; + } } diff --git a/src/kademlia/core/KadConfiguration.java b/src/kademlia/core/KadConfiguration.java index 99a305f..e77b65e 100644 --- a/src/kademlia/core/KadConfiguration.java +++ b/src/kademlia/core/KadConfiguration.java @@ -8,7 +8,7 @@ package kademlia.core; */ public interface KadConfiguration { - + /** * @return Interval in milliseconds between execution of RestoreOperations. */ @@ -48,11 +48,16 @@ public interface KadConfiguration 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 * * @return The folder path */ public String getNodeDataFolder(String ownerId); + + /** + * @return Whether we're in a testing or production system. + */ + public boolean isTesting(); } diff --git a/src/kademlia/core/KadServer.java b/src/kademlia/core/KadServer.java index 8afd3e9..b895612 100644 --- a/src/kademlia/core/KadServer.java +++ b/src/kademlia/core/KadServer.java @@ -208,6 +208,14 @@ public class KadServer /* Lets inform the statistician that we've received some data */ 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 */ try (ByteArrayInputStream bin = new ByteArrayInputStream(packet.getData(), packet.getOffset(), packet.getLength()); DataInputStream din = new DataInputStream(bin);)