From d920f2621ef4e54e018de8fd76350107dda0f439 Mon Sep 17 00:00:00 2001 From: Joshua Kissoon Date: Mon, 5 May 2014 14:54:49 +0530 Subject: [PATCH] Added synchronization to prevent concurrency exceptions --- src/kademlia/core/DefaultConfiguration.java | 4 ++-- src/kademlia/dht/DHT.java | 6 +++--- src/kademlia/dht/StoredContentManager.java | 2 +- src/kademlia/message/ContentLookupReceiver.java | 4 ++-- src/kademlia/operation/BucketRefreshOperation.java | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/kademlia/core/DefaultConfiguration.java b/src/kademlia/core/DefaultConfiguration.java index 1cc6520..3ce5f8a 100644 --- a/src/kademlia/core/DefaultConfiguration.java +++ b/src/kademlia/core/DefaultConfiguration.java @@ -10,11 +10,11 @@ import java.io.File; public class DefaultConfiguration implements KadConfiguration { - private final static long RESTORE_INTERVAL = 10 * 1000; // Default at 1 hour + private final static long RESTORE_INTERVAL = 5 * 1000; // Default at 1 hour private final static long RESPONSE_TIMEOUT = 1500; private final static long OPERATION_TIMEOUT = 3000; private final static int CONCURRENCY = 10; - private final static int K = 10; + private final static int K = 4; private final static int RCSIZE = 3; private final static int STALE = 1; private final static String LOCAL_FOLDER = "kademlia"; diff --git a/src/kademlia/dht/DHT.java b/src/kademlia/dht/DHT.java index ae631e1..f6fe70a 100644 --- a/src/kademlia/dht/DHT.java +++ b/src/kademlia/dht/DHT.java @@ -100,7 +100,7 @@ public class DHT /* We have this content, but not the latest version, lets delete it so the new version will be added below */ try { - System.out.println("Removing older content to update it"); + //System.out.println("Removing older content to update it"); this.remove(content.getContentMetadata()); } catch (ContentNotFoundException ex) @@ -116,7 +116,7 @@ public class DHT */ try { - System.out.println("Adding new content."); + //System.out.println("Adding new content."); /* Keep track of this content in the entries manager */ StorageEntryMetadata sEntry = this.entriesManager.put(content.getContentMetadata()); @@ -292,7 +292,7 @@ public class DHT /** * @return A List of all StorageEntries for this node */ - public List getStorageEntries() + public synchronized List getStorageEntries() { return entriesManager.getAllEntries(); } diff --git a/src/kademlia/dht/StoredContentManager.java b/src/kademlia/dht/StoredContentManager.java index b3a6318..6b1d0c4 100644 --- a/src/kademlia/dht/StoredContentManager.java +++ b/src/kademlia/dht/StoredContentManager.java @@ -143,7 +143,7 @@ class StoredContentManager /** * @return A list of all storage entries */ - public List getAllEntries() + public synchronized List getAllEntries() { List entriesRet = new ArrayList<>(); diff --git a/src/kademlia/message/ContentLookupReceiver.java b/src/kademlia/message/ContentLookupReceiver.java index 8417384..f0212d3 100644 --- a/src/kademlia/message/ContentLookupReceiver.java +++ b/src/kademlia/message/ContentLookupReceiver.java @@ -35,8 +35,8 @@ public class ContentLookupReceiver implements Receiver ContentLookupMessage msg = (ContentLookupMessage) incoming; this.localNode.getRoutingTable().insert(msg.getOrigin()); - System.out.println("Received request for content with GetParameter" + msg.getParameters()); - System.out.println("Have Content? " + this.dht.contains(msg.getParameters())); + //System.out.println("Received request for content with GetParameter" + msg.getParameters()); + //System.out.println("Have Content? " + this.dht.contains(msg.getParameters())); /* Check if we can have this data */ if (this.dht.contains(msg.getParameters())) diff --git a/src/kademlia/operation/BucketRefreshOperation.java b/src/kademlia/operation/BucketRefreshOperation.java index 9f364f0..3282a7c 100644 --- a/src/kademlia/operation/BucketRefreshOperation.java +++ b/src/kademlia/operation/BucketRefreshOperation.java @@ -57,7 +57,7 @@ public class BucketRefreshOperation implements Operation } catch (IOException e) { - System.err.println("Bucket Refresh Operation Failed. Msg: " + e.getMessage()); + //System.err.println("Bucket Refresh Operation Failed. Msg: " + e.getMessage()); } } }.start();