From 111cdc9e05b7fd4c9424a15802740ca1a0221843 Mon Sep 17 00:00:00 2001 From: Joshua Kissoon Date: Sat, 10 May 2014 19:28:19 +0530 Subject: [PATCH] KadBucket - Updated toString to display stale count of a contact DHT - Updated toString to print a count of content. --- src/kademlia/core/DefaultConfiguration.java | 2 +- src/kademlia/dht/StoredContentManager.java | 3 +++ src/kademlia/operation/NodeLookupOperation.java | 13 +++++++++---- src/kademlia/routing/KadBucketImpl.java | 3 +++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/kademlia/core/DefaultConfiguration.java b/src/kademlia/core/DefaultConfiguration.java index 8782d59..cb2e1b3 100644 --- a/src/kademlia/core/DefaultConfiguration.java +++ b/src/kademlia/core/DefaultConfiguration.java @@ -10,7 +10,7 @@ import java.io.File; public class DefaultConfiguration implements KadConfiguration { - private final static long RESTORE_INTERVAL = 60 * 1000; // in milliseconds + private final static long RESTORE_INTERVAL = 20 * 1000; // in milliseconds private final static long RESPONSE_TIMEOUT = 1500; private final static long OPERATION_TIMEOUT = 3000; private final static int CONCURRENCY = 10; diff --git a/src/kademlia/dht/StoredContentManager.java b/src/kademlia/dht/StoredContentManager.java index 98099c9..c414d52 100644 --- a/src/kademlia/dht/StoredContentManager.java +++ b/src/kademlia/dht/StoredContentManager.java @@ -179,6 +179,7 @@ class StoredContentManager public synchronized String toString() { StringBuilder sb = new StringBuilder("Stored Content: \n"); + int count = 0; for (List es : this.entries.values()) { if (entries.size() < 1) @@ -188,6 +189,8 @@ class StoredContentManager for (StorageEntryMetadata e : es) { + sb.append(++count); + sb.append(". "); sb.append(e); sb.append("\n"); } diff --git a/src/kademlia/operation/NodeLookupOperation.java b/src/kademlia/operation/NodeLookupOperation.java index dea5278..37af860 100644 --- a/src/kademlia/operation/NodeLookupOperation.java +++ b/src/kademlia/operation/NodeLookupOperation.java @@ -100,7 +100,7 @@ public class NodeLookupOperation implements Operation, Receiver /* If we haven't finished as yet, wait for a maximum of config.operationTimeout() time */ int totalTimeWaited = 0; - int timeInterval = 10; // We re-check every 300 milliseconds + int timeInterval = 10; // We re-check every n milliseconds while (totalTimeWaited < this.config.operationTimeout()) { if (!this.askNodesorFinish()) @@ -113,10 +113,10 @@ public class NodeLookupOperation implements Operation, Receiver break; } } - + /** - * There is no need to throw an exception here! - * If the operation times out means we didn't get replies from all nodes, + * There is no need to throw an exception here! + * If the operation times out means we didn't get replies from all nodes, * so lets just simply return the K-Closest nodes we knoe */ // if (error) @@ -273,6 +273,11 @@ public class NodeLookupOperation implements Operation, Receiver @Override public synchronized void receive(Message incoming, int comm) throws IOException { + if (!(incoming instanceof NodeReplyMessage)) + { + /* Not sure why we get a message of a different type here... @todo Figure it out. */ + return; + } /* We receive a NodeReplyMessage with a set of nodes, read this message */ NodeReplyMessage msg = (NodeReplyMessage) incoming; diff --git a/src/kademlia/routing/KadBucketImpl.java b/src/kademlia/routing/KadBucketImpl.java index c049586..c6012e2 100644 --- a/src/kademlia/routing/KadBucketImpl.java +++ b/src/kademlia/routing/KadBucketImpl.java @@ -248,6 +248,9 @@ public class KadBucketImpl implements KadBucket { sb.append("Node: "); sb.append(n.getNode().getNodeId().toString()); + sb.append(" (stale: "); + sb.append(n.staleCount()); + sb.append(")"); sb.append("\n"); }