From 58696d627a60157050fa0b504658d688624b6c14 Mon Sep 17 00:00:00 2001 From: Joshua Kissoon Date: Fri, 9 May 2014 16:05:14 +0530 Subject: [PATCH] Made a few KadBucket methods private Changed the comparison of KademliaId to use the hashcode --- src/kademlia/core/DefaultConfiguration.java | 2 +- src/kademlia/node/KademliaId.java | 2 +- src/kademlia/node/Node.java | 4 ++-- src/kademlia/routing/KadBucketImpl.java | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/kademlia/core/DefaultConfiguration.java b/src/kademlia/core/DefaultConfiguration.java index d23282a..8782d59 100644 --- a/src/kademlia/core/DefaultConfiguration.java +++ b/src/kademlia/core/DefaultConfiguration.java @@ -14,7 +14,7 @@ public class DefaultConfiguration implements KadConfiguration 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 = 5; private final static int RCSIZE = 3; private final static int STALE = 1; private final static String LOCAL_FOLDER = "kademlia"; diff --git a/src/kademlia/node/KademliaId.java b/src/kademlia/node/KademliaId.java index ddd2b9b..1664cf0 100644 --- a/src/kademlia/node/KademliaId.java +++ b/src/kademlia/node/KademliaId.java @@ -95,7 +95,7 @@ public class KademliaId implements Streamable if (o instanceof KademliaId) { KademliaId nid = (KademliaId) o; - return Arrays.equals(this.getBytes(), nid.getBytes()); + return this.hashCode() == nid.hashCode(); } return false; } diff --git a/src/kademlia/node/Node.java b/src/kademlia/node/Node.java index 4a56320..a5185d1 100644 --- a/src/kademlia/node/Node.java +++ b/src/kademlia/node/Node.java @@ -111,11 +111,11 @@ public class Node implements Streamable if (o instanceof Node) { Node n = (Node) o; - if (o == this) + if (n == this) { return true; } - return this.getNodeId().equals(((Node) o).getNodeId()); + return this.getNodeId().equals(n.getNodeId()); } return false; } diff --git a/src/kademlia/routing/KadBucketImpl.java b/src/kademlia/routing/KadBucketImpl.java index 84e4360..c049586 100644 --- a/src/kademlia/routing/KadBucketImpl.java +++ b/src/kademlia/routing/KadBucketImpl.java @@ -142,7 +142,7 @@ public class KadBucketImpl implements KadBucket return true; } - public synchronized Contact getFromContacts(Node n) + private synchronized Contact getFromContacts(Node n) { for (Contact c : this.contacts) { @@ -156,7 +156,7 @@ public class KadBucketImpl implements KadBucket throw new NoSuchElementException("The contact does not exist in the contacts list."); } - public synchronized Contact removeFromContacts(Node n) + private synchronized Contact removeFromContacts(Node n) { for (Contact c : this.contacts) { @@ -223,7 +223,7 @@ public class KadBucketImpl implements KadBucket } } - public synchronized Contact removeFromReplacementCache(Node n) + private synchronized Contact removeFromReplacementCache(Node n) { for (Contact c : this.replacementCache) {