diff --git a/src/kademlia/Statistics.java b/src/kademlia/Statistics.java index dbdd6b9..c76ac3e 100644 --- a/src/kademlia/Statistics.java +++ b/src/kademlia/Statistics.java @@ -1,7 +1,9 @@ package kademlia; /** - * Class that keeps statistics for a single run + * Class that keeps statistics for this Kademlia instance. + * + * These statistics are temporary and will be lost when Kad is shut down. * * @author Joshua Kissoon * @since 20140505 @@ -9,9 +11,48 @@ package kademlia; public class Statistics { + /* How much data was sent and received by the server over the network */ + private long totalDataSent, totalDataReceived; + + + { + this.totalDataSent = 0; + this.totalDataReceived = 0; + } + /** - * How much data was sent and received by the server over the network + * Used to indicate some data is sent + * + * @param size The size of the data sent */ - public static long dataSent = 0; - public static long dataReceived = 0; + 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; + } + + /** + * @return The total data received + */ + public long getTotalDataReceived() + { + return this.totalDataReceived; + } } diff --git a/src/kademlia/core/KadServer.java b/src/kademlia/core/KadServer.java index 7fb8da2..5dfa4af 100644 --- a/src/kademlia/core/KadServer.java +++ b/src/kademlia/core/KadServer.java @@ -13,7 +13,6 @@ import java.util.Map; import java.util.Random; import java.util.Timer; import java.util.TimerTask; -import kademlia.Statistics; import kademlia.exceptions.KadServerDownException; import kademlia.message.Message; import kademlia.message.MessageFactory; @@ -36,7 +35,6 @@ public class KadServer private final transient KadConfiguration config; /* Server Objects */ - private final int udpPort; private final DatagramSocket socket; private transient boolean isRunning; private final Map receivers; @@ -68,7 +66,6 @@ public class KadServer */ public KadServer(int udpPort, MessageFactory mFactory, Node localNode, KadConfiguration config) throws SocketException { - this.udpPort = udpPort; this.config = config; this.socket = new DatagramSocket(udpPort); @@ -196,7 +193,7 @@ public class KadServer DatagramPacket packet = new DatagramPacket(buffer, buffer.length); socket.receive(packet); - Statistics.dataReceived += packet.getLength(); + //Statistics.dataReceived += packet.getLength(); //System.out.println("Received packet of size: " + packet.getLength()); /* We've received a packet, now handle it */