From 3ab6b3d2abc4b18928aeedd3bf8da61d3b90622e Mon Sep 17 00:00:00 2001 From: Joshua Kissoon Date: Fri, 9 May 2014 11:03:00 +0530 Subject: [PATCH] Renamed NodeId to KademliaId Since that's basically what it is! --- src/kademlia/KademliaNode.java | 4 ++-- src/kademlia/dht/DHT.java | 6 ++--- src/kademlia/dht/GetParameter.java | 10 ++++---- src/kademlia/dht/KadContent.java | 4 ++-- src/kademlia/dht/StorageEntryMetadata.java | 6 ++--- src/kademlia/dht/StoredContentManager.java | 4 ++-- src/kademlia/message/NodeLookupMessage.java | 10 ++++---- .../node/{NodeId.java => KademliaId.java} | 24 +++++++++---------- src/kademlia/node/KeyComparator.java | 2 +- src/kademlia/node/Node.java | 8 +++---- .../operation/BucketRefreshOperation.java | 6 ++--- .../operation/NodeLookupOperation.java | 4 ++-- src/kademlia/routing/KadRoutingTable.java | 6 ++--- src/kademlia/routing/RoutingTable.java | 10 ++++---- .../tests/AutoRefreshOperationTest.java | 14 +++++------ .../tests/AutoRefreshOperationTest2.java | 10 ++++---- src/kademlia/tests/ContentSendingTest.java | 6 ++--- src/kademlia/tests/ContentUpdatingTest.java | 6 ++--- src/kademlia/tests/DHTContentImpl.java | 10 ++++---- src/kademlia/tests/NodeConnectionTest.java | 10 ++++---- src/kademlia/tests/RefreshOperationTest.java | 6 ++--- .../tests/RoutingTableSimulation.java | 12 +++++----- .../tests/RoutingTableStateTesting.java | 22 ++++++++--------- src/kademlia/tests/SaveStateTest.java | 12 +++++----- src/kademlia/tests/SaveStateTest2.java | 6 ++--- src/kademlia/tests/SimpleMessageTest.java | 6 ++--- 26 files changed, 112 insertions(+), 112 deletions(-) rename src/kademlia/node/{NodeId.java => KademliaId.java} (91%) diff --git a/src/kademlia/KademliaNode.java b/src/kademlia/KademliaNode.java index 6527661..4eaec58 100644 --- a/src/kademlia/KademliaNode.java +++ b/src/kademlia/KademliaNode.java @@ -22,7 +22,7 @@ import kademlia.exceptions.ContentNotFoundException; import kademlia.exceptions.RoutingException; import kademlia.message.MessageFactory; import kademlia.node.Node; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; import kademlia.operation.ConnectOperation; import kademlia.operation.ContentLookupOperation; import kademlia.operation.Operation; @@ -158,7 +158,7 @@ public class KademliaNode ); } - public KademliaNode(String ownerId, NodeId defaultId, int udpPort) throws IOException + public KademliaNode(String ownerId, KademliaId defaultId, int udpPort) throws IOException { this( ownerId, diff --git a/src/kademlia/dht/DHT.java b/src/kademlia/dht/DHT.java index 8d22f83..5e6bf8f 100644 --- a/src/kademlia/dht/DHT.java +++ b/src/kademlia/dht/DHT.java @@ -12,7 +12,7 @@ import java.util.NoSuchElementException; import kademlia.core.KadConfiguration; import kademlia.exceptions.ContentExistException; import kademlia.exceptions.ContentNotFoundException; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; import kademlia.util.serializer.JsonSerializer; import kademlia.util.serializer.KadSerializer; @@ -155,7 +155,7 @@ public class DHT * * @return A KadContent object */ - private StorageEntry retrieve(NodeId key, int hashCode) throws FileNotFoundException, IOException, ClassNotFoundException + private StorageEntry retrieve(KademliaId key, int hashCode) throws FileNotFoundException, IOException, ClassNotFoundException { String folder = this.getContentStorageFolderName(key); DataInputStream din = new DataInputStream(new FileInputStream(folder + File.separator + hashCode + ".kct")); @@ -270,7 +270,7 @@ public class DHT * * @return String The name of the folder */ - private String getContentStorageFolderName(NodeId key) + private String getContentStorageFolderName(KademliaId key) { /** * Each content is stored in a folder named after the first 10 characters of the NodeId diff --git a/src/kademlia/dht/GetParameter.java b/src/kademlia/dht/GetParameter.java index ecc996a..c1c12cf 100644 --- a/src/kademlia/dht/GetParameter.java +++ b/src/kademlia/dht/GetParameter.java @@ -1,6 +1,6 @@ package kademlia.dht; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * A GET request can get content based on Key, Owner, Type, etc @@ -15,7 +15,7 @@ import kademlia.node.NodeId; public class GetParameter { - private NodeId key; + private KademliaId key; private String ownerId = null; private String type = null; @@ -25,7 +25,7 @@ public class GetParameter * @param key * @param type */ - public GetParameter(NodeId key, String type) + public GetParameter(KademliaId key, String type) { this.key = key; this.type = type; @@ -38,7 +38,7 @@ public class GetParameter * @param type * @param owner */ - public GetParameter(NodeId key, String type, String owner) + public GetParameter(KademliaId key, String type, String owner) { this(key, owner); this.type = type; @@ -84,7 +84,7 @@ public class GetParameter } } - public NodeId getKey() + public KademliaId getKey() { return this.key; } diff --git a/src/kademlia/dht/KadContent.java b/src/kademlia/dht/KadContent.java index ff15f9c..9cae1dc 100644 --- a/src/kademlia/dht/KadContent.java +++ b/src/kademlia/dht/KadContent.java @@ -1,6 +1,6 @@ package kademlia.dht; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * Any piece of content that needs to be stored on the DHT @@ -15,7 +15,7 @@ public interface KadContent /** * @return NodeId The DHT key for this content */ - public NodeId getKey(); + public KademliaId getKey(); /** * @return String The type of content diff --git a/src/kademlia/dht/StorageEntryMetadata.java b/src/kademlia/dht/StorageEntryMetadata.java index 2620750..6c2d91a 100644 --- a/src/kademlia/dht/StorageEntryMetadata.java +++ b/src/kademlia/dht/StorageEntryMetadata.java @@ -1,7 +1,7 @@ package kademlia.dht; import java.util.Objects; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * Keeps track of data for a Content stored in the DHT @@ -13,7 +13,7 @@ import kademlia.node.NodeId; public class StorageEntryMetadata { - private final NodeId key; + private final KademliaId key; private final String ownerId; private final String type; private final int contentHash; @@ -33,7 +33,7 @@ public class StorageEntryMetadata this.lastRepublished = System.currentTimeMillis() / 1000L; } - public NodeId getKey() + public KademliaId getKey() { return this.key; } diff --git a/src/kademlia/dht/StoredContentManager.java b/src/kademlia/dht/StoredContentManager.java index 0c6ee95..98099c9 100644 --- a/src/kademlia/dht/StoredContentManager.java +++ b/src/kademlia/dht/StoredContentManager.java @@ -7,7 +7,7 @@ import java.util.Map; import java.util.NoSuchElementException; import kademlia.exceptions.ContentExistException; import kademlia.exceptions.ContentNotFoundException; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * It would be infeasible to keep all content in memory to be send when requested @@ -20,7 +20,7 @@ import kademlia.node.NodeId; class StoredContentManager { - private final Map> entries; + private final Map> entries; { diff --git a/src/kademlia/message/NodeLookupMessage.java b/src/kademlia/message/NodeLookupMessage.java index 865f161..d1a9b5d 100644 --- a/src/kademlia/message/NodeLookupMessage.java +++ b/src/kademlia/message/NodeLookupMessage.java @@ -4,7 +4,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import kademlia.node.Node; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * A message sent to other nodes requesting the K-Closest nodes to a key sent in this message. @@ -16,7 +16,7 @@ public class NodeLookupMessage implements Message { private Node origin; - private NodeId lookupId; + private KademliaId lookupId; public static final byte CODE = 0x05; @@ -26,7 +26,7 @@ public class NodeLookupMessage implements Message * @param origin The Node from which the message is coming from * @param lookup The key for which to lookup nodes for */ - public NodeLookupMessage(Node origin, NodeId lookup) + public NodeLookupMessage(Node origin, KademliaId lookup) { this.origin = origin; this.lookupId = lookup; @@ -41,7 +41,7 @@ public class NodeLookupMessage implements Message public final void fromStream(DataInputStream in) throws IOException { this.origin = new Node(in); - this.lookupId = new NodeId(in); + this.lookupId = new KademliaId(in); } @Override @@ -56,7 +56,7 @@ public class NodeLookupMessage implements Message return this.origin; } - public NodeId getLookupId() + public KademliaId getLookupId() { return this.lookupId; } diff --git a/src/kademlia/node/NodeId.java b/src/kademlia/node/KademliaId.java similarity index 91% rename from src/kademlia/node/NodeId.java rename to src/kademlia/node/KademliaId.java index 0341617..ddd2b9b 100644 --- a/src/kademlia/node/NodeId.java +++ b/src/kademlia/node/KademliaId.java @@ -14,7 +14,7 @@ import java.util.BitSet; import java.util.Random; import kademlia.message.Streamable; -public class NodeId implements Streamable +public class KademliaId implements Streamable { public final transient static int ID_LENGTH = 160; @@ -25,7 +25,7 @@ public class NodeId implements Streamable * * @param data The user generated key string */ - public NodeId(String data) + public KademliaId(String data) { keyBytes = data.getBytes(); if (keyBytes.length != ID_LENGTH / 8) @@ -37,7 +37,7 @@ public class NodeId implements Streamable /** * Generate a random key */ - public NodeId() + public KademliaId() { keyBytes = new byte[ID_LENGTH / 8]; new Random().nextBytes(keyBytes); @@ -48,7 +48,7 @@ public class NodeId implements Streamable * * @param bytes */ - public NodeId(byte[] bytes) + public KademliaId(byte[] bytes) { if (bytes.length != ID_LENGTH / 8) { @@ -64,7 +64,7 @@ public class NodeId implements Streamable * * @throws IOException */ - public NodeId(DataInputStream in) throws IOException + public KademliaId(DataInputStream in) throws IOException { this.fromStream(in); } @@ -92,9 +92,9 @@ public class NodeId implements Streamable @Override public boolean equals(Object o) { - if (o instanceof NodeId) + if (o instanceof KademliaId) { - NodeId nid = (NodeId) o; + KademliaId nid = (KademliaId) o; return Arrays.equals(this.getBytes(), nid.getBytes()); } return false; @@ -115,7 +115,7 @@ public class NodeId implements Streamable * * @return The distance of this NodeId from the given NodeId */ - public NodeId xor(NodeId nid) + public KademliaId xor(KademliaId nid) { byte[] result = new byte[ID_LENGTH / 8]; byte[] nidBytes = nid.getBytes(); @@ -125,7 +125,7 @@ public class NodeId implements Streamable result[i] = (byte) (this.keyBytes[i] ^ nidBytes[i]); } - NodeId resNid = new NodeId(result); + KademliaId resNid = new KademliaId(result); return resNid; } @@ -137,7 +137,7 @@ public class NodeId implements Streamable * * @return NodeId The newly generated NodeId */ - public NodeId generateNodeIdByDistance(int distance) + public KademliaId generateNodeIdByDistance(int distance) { byte[] result = new byte[ID_LENGTH / 8]; @@ -169,7 +169,7 @@ public class NodeId implements Streamable result[i] = Byte.MAX_VALUE; } - return this.xor(new NodeId(result)); + return this.xor(new KademliaId(result)); } /** @@ -221,7 +221,7 @@ public class NodeId implements Streamable * * @return Integer The distance */ - public int getDistance(NodeId to) + public int getDistance(KademliaId to) { /** * Compute the xor of this and to diff --git a/src/kademlia/node/KeyComparator.java b/src/kademlia/node/KeyComparator.java index e464cc7..01bbbe4 100644 --- a/src/kademlia/node/KeyComparator.java +++ b/src/kademlia/node/KeyComparator.java @@ -17,7 +17,7 @@ public class KeyComparator implements Comparator /** * @param key The NodeId relative to which the distance should be measured. */ - public KeyComparator(NodeId key) + public KeyComparator(KademliaId key) { this.key = key.getInt(); } diff --git a/src/kademlia/node/Node.java b/src/kademlia/node/Node.java index 8f0f30b..4a56320 100644 --- a/src/kademlia/node/Node.java +++ b/src/kademlia/node/Node.java @@ -18,12 +18,12 @@ import kademlia.message.Streamable; public class Node implements Streamable { - private NodeId nodeId; + private KademliaId nodeId; private InetAddress inetAddress; private int port; private final String strRep; - public Node(NodeId nid, InetAddress ip, int port) + public Node(KademliaId nid, InetAddress ip, int port) { this.nodeId = nid; this.inetAddress = ip; @@ -57,7 +57,7 @@ public class Node implements Streamable /** * @return The NodeId object of this node */ - public NodeId getNodeId() + public KademliaId getNodeId() { return this.nodeId; } @@ -94,7 +94,7 @@ public class Node implements Streamable public final void fromStream(DataInputStream in) throws IOException { /* Load the NodeId */ - this.nodeId = new NodeId(in); + this.nodeId = new KademliaId(in); /* Load the IP Address */ byte[] ip = new byte[4]; diff --git a/src/kademlia/operation/BucketRefreshOperation.java b/src/kademlia/operation/BucketRefreshOperation.java index 2dcf97e..226ee77 100644 --- a/src/kademlia/operation/BucketRefreshOperation.java +++ b/src/kademlia/operation/BucketRefreshOperation.java @@ -4,7 +4,7 @@ import java.io.IOException; import kademlia.KademliaNode; import kademlia.core.KadConfiguration; import kademlia.core.KadServer; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * At each time interval t, nodes need to refresh their K-Buckets @@ -40,10 +40,10 @@ public class BucketRefreshOperation implements Operation @Override public synchronized void execute() throws IOException { - for (int i = 1; i < NodeId.ID_LENGTH; i++) + for (int i = 1; i < KademliaId.ID_LENGTH; i++) { /* Construct a NodeId that is i bits away from the current node Id */ - final NodeId current = this.localNode.getNode().getNodeId().generateNodeIdByDistance(i); + final KademliaId current = this.localNode.getNode().getNodeId().generateNodeIdByDistance(i); /* Run the Node Lookup Operation, each in a different thread to speed up things */ new Thread() diff --git a/src/kademlia/operation/NodeLookupOperation.java b/src/kademlia/operation/NodeLookupOperation.java index d25a415..dea5278 100644 --- a/src/kademlia/operation/NodeLookupOperation.java +++ b/src/kademlia/operation/NodeLookupOperation.java @@ -17,7 +17,7 @@ import kademlia.message.NodeLookupMessage; import kademlia.message.NodeReplyMessage; import kademlia.node.KeyComparator; import kademlia.node.Node; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * Finds the K closest nodes to a specified identifier @@ -62,7 +62,7 @@ public class NodeLookupOperation implements Operation, Receiver * @param lookupId The ID for which to find nodes close to * @param config */ - public NodeLookupOperation(KadServer server, KademliaNode localNode, NodeId lookupId, KadConfiguration config) + public NodeLookupOperation(KadServer server, KademliaNode localNode, KademliaId lookupId, KadConfiguration config) { this.server = server; this.localNode = localNode; diff --git a/src/kademlia/routing/KadRoutingTable.java b/src/kademlia/routing/KadRoutingTable.java index d1c1b49..6abdcc1 100644 --- a/src/kademlia/routing/KadRoutingTable.java +++ b/src/kademlia/routing/KadRoutingTable.java @@ -3,7 +3,7 @@ package kademlia.routing; import java.util.List; import kademlia.core.KadConfiguration; import kademlia.node.Node; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * Specification for Kademlia's Routing Table @@ -47,7 +47,7 @@ public interface KadRoutingTable * * @return Integer The bucket ID in which the given node should be placed. */ - public int getBucketId(NodeId nid); + public int getBucketId(KademliaId nid); /** * Find the closest set of contacts to a given NodeId @@ -57,7 +57,7 @@ public interface KadRoutingTable * * @return List A List of contacts closest to target */ - public List findClosest(NodeId target, int numNodesRequired); + public List findClosest(KademliaId target, int numNodesRequired); /** * @return List A List of all Nodes in this RoutingTable diff --git a/src/kademlia/routing/RoutingTable.java b/src/kademlia/routing/RoutingTable.java index 1c8418c..e2695a5 100644 --- a/src/kademlia/routing/RoutingTable.java +++ b/src/kademlia/routing/RoutingTable.java @@ -6,7 +6,7 @@ import java.util.TreeSet; import kademlia.core.KadConfiguration; import kademlia.node.KeyComparator; import kademlia.node.Node; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * Implementation of a Kademlia routing table @@ -40,8 +40,8 @@ public class RoutingTable implements KadRoutingTable @Override public final void initialize() { - this.buckets = new KadBucket[NodeId.ID_LENGTH]; - for (int i = 0; i < NodeId.ID_LENGTH; i++) + this.buckets = new KadBucket[KademliaId.ID_LENGTH]; + for (int i = 0; i < KademliaId.ID_LENGTH; i++) { buckets[i] = new KadBucketImpl(i, this.config); } @@ -83,7 +83,7 @@ public class RoutingTable implements KadRoutingTable * @return Integer The bucket ID in which the given node should be placed. */ @Override - public final int getBucketId(NodeId nid) + public final int getBucketId(KademliaId nid) { int bId = this.localNode.getNodeId().getDistance(nid) - 1; @@ -100,7 +100,7 @@ public class RoutingTable implements KadRoutingTable * @return List A List of contacts closest to target */ @Override - public synchronized final List findClosest(NodeId target, int numNodesRequired) + public synchronized final List findClosest(KademliaId target, int numNodesRequired) { TreeSet sortedSet = new TreeSet<>(new KeyComparator(target)); sortedSet.addAll(this.getAllNodes()); diff --git a/src/kademlia/tests/AutoRefreshOperationTest.java b/src/kademlia/tests/AutoRefreshOperationTest.java index 592a397..6e2fc3e 100644 --- a/src/kademlia/tests/AutoRefreshOperationTest.java +++ b/src/kademlia/tests/AutoRefreshOperationTest.java @@ -5,7 +5,7 @@ import java.util.TimerTask; import kademlia.core.DefaultConfiguration; import kademlia.KademliaNode; import kademlia.core.KadConfiguration; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * Testing the Kademlia Auto Content and Node table refresh operations @@ -21,11 +21,11 @@ public class AutoRefreshOperationTest try { /* Setting up 2 Kad networks */ - final KademliaNode kad1 = new KademliaNode("JoshuaK", new NodeId("ASF456789djem45674DH"), 12049); - final KademliaNode kad2 = new KademliaNode("Crystal", new NodeId("AJDHR678947584567464"), 4585); - final KademliaNode kad3 = new KademliaNode("Shameer", new NodeId("AS84k6789KRNS45KFJ8W"), 8104); - final KademliaNode kad4 = new KademliaNode("Lokesh.", new NodeId("ASF45678947A845674GG"), 8335); - final KademliaNode kad5 = new KademliaNode("Chandu.", new NodeId("AS84kUD894758456dyrj"), 13345); + final KademliaNode kad1 = new KademliaNode("JoshuaK", new KademliaId("ASF456789djem45674DH"), 12049); + final KademliaNode kad2 = new KademliaNode("Crystal", new KademliaId("AJDHR678947584567464"), 4585); + final KademliaNode kad3 = new KademliaNode("Shameer", new KademliaId("AS84k6789KRNS45KFJ8W"), 8104); + final KademliaNode kad4 = new KademliaNode("Lokesh.", new KademliaId("ASF45678947A845674GG"), 8335); + final KademliaNode kad5 = new KademliaNode("Chandu.", new KademliaId("AS84kUD894758456dyrj"), 13345); /* Connecting nodes */ System.out.println("Connecting Nodes"); @@ -34,7 +34,7 @@ public class AutoRefreshOperationTest kad4.bootstrap(kad2.getNode()); kad5.bootstrap(kad4.getNode()); - DHTContentImpl c = new DHTContentImpl(new NodeId("AS84k678947584567465"), kad1.getOwnerId()); + DHTContentImpl c = new DHTContentImpl(new KademliaId("AS84k678947584567465"), kad1.getOwnerId()); c.setData("Setting the data"); System.out.println("\n Content ID: " + c.getKey()); diff --git a/src/kademlia/tests/AutoRefreshOperationTest2.java b/src/kademlia/tests/AutoRefreshOperationTest2.java index a14dbd6..8536567 100644 --- a/src/kademlia/tests/AutoRefreshOperationTest2.java +++ b/src/kademlia/tests/AutoRefreshOperationTest2.java @@ -5,7 +5,7 @@ import java.util.TimerTask; import kademlia.core.DefaultConfiguration; import kademlia.KademliaNode; import kademlia.core.KadConfiguration; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * Testing the Kademlia Auto Content and Node table refresh operations @@ -21,16 +21,16 @@ public class AutoRefreshOperationTest2 try { /* Setting up 2 Kad networks */ - final KademliaNode kad1 = new KademliaNode("JoshuaK", new NodeId("ASF456789djem4567463"), 12049); - final KademliaNode kad2 = new KademliaNode("Crystal", new NodeId("AS84k678DJRW84567465"), 4585); - final KademliaNode kad3 = new KademliaNode("Shameer", new NodeId("AS84k67894758456746A"), 8104); + final KademliaNode kad1 = new KademliaNode("JoshuaK", new KademliaId("ASF456789djem4567463"), 12049); + final KademliaNode kad2 = new KademliaNode("Crystal", new KademliaId("AS84k678DJRW84567465"), 4585); + final KademliaNode kad3 = new KademliaNode("Shameer", new KademliaId("AS84k67894758456746A"), 8104); /* Connecting nodes */ System.out.println("Connecting Nodes"); kad2.bootstrap(kad1.getNode()); kad3.bootstrap(kad2.getNode()); - DHTContentImpl c = new DHTContentImpl(new NodeId("AS84k678947584567465"), kad1.getOwnerId()); + DHTContentImpl c = new DHTContentImpl(new KademliaId("AS84k678947584567465"), kad1.getOwnerId()); c.setData("Setting the data"); kad1.putLocally(c); diff --git a/src/kademlia/tests/ContentSendingTest.java b/src/kademlia/tests/ContentSendingTest.java index ba591d6..92caa98 100644 --- a/src/kademlia/tests/ContentSendingTest.java +++ b/src/kademlia/tests/ContentSendingTest.java @@ -5,7 +5,7 @@ import kademlia.dht.GetParameter; import kademlia.KademliaNode; import kademlia.dht.StorageEntry; import kademlia.exceptions.ContentNotFoundException; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * Testing sending and receiving content between 2 Nodes on a network @@ -21,9 +21,9 @@ public class ContentSendingTest try { /* Setting up 2 Kad networks */ - KademliaNode kad1 = new KademliaNode("JoshuaK", new NodeId("ASF45678947584567467"), 7574); + KademliaNode kad1 = new KademliaNode("JoshuaK", new KademliaId("ASF45678947584567467"), 7574); System.out.println("Created Node Kad 1: " + kad1.getNode().getNodeId()); - KademliaNode kad2 = new KademliaNode("Crystal", new NodeId("ASERTKJDHGVHERJHGFLK"), 7572); + KademliaNode kad2 = new KademliaNode("Crystal", new KademliaId("ASERTKJDHGVHERJHGFLK"), 7572); System.out.println("Created Node Kad 2: " + kad2.getNode().getNodeId()); kad2.bootstrap(kad1.getNode()); diff --git a/src/kademlia/tests/ContentUpdatingTest.java b/src/kademlia/tests/ContentUpdatingTest.java index 03ae45d..9b35883 100644 --- a/src/kademlia/tests/ContentUpdatingTest.java +++ b/src/kademlia/tests/ContentUpdatingTest.java @@ -5,7 +5,7 @@ import kademlia.dht.GetParameter; import kademlia.KademliaNode; import kademlia.dht.StorageEntry; import kademlia.exceptions.ContentNotFoundException; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * Testing sending and receiving content between 2 Nodes on a network @@ -21,9 +21,9 @@ public class ContentUpdatingTest try { /* Setting up 2 Kad networks */ - KademliaNode kad1 = new KademliaNode("JoshuaK", new NodeId("ASF45678947584567467"), 7574); + KademliaNode kad1 = new KademliaNode("JoshuaK", new KademliaId("ASF45678947584567467"), 7574); System.out.println("Created Node Kad 1: " + kad1.getNode().getNodeId()); - KademliaNode kad2 = new KademliaNode("Crystal", new NodeId("ASERTKJDHGVHERJHGFLK"), 7572); + KademliaNode kad2 = new KademliaNode("Crystal", new KademliaId("ASERTKJDHGVHERJHGFLK"), 7572); System.out.println("Created Node Kad 2: " + kad2.getNode().getNodeId()); kad2.bootstrap(kad1.getNode()); diff --git a/src/kademlia/tests/DHTContentImpl.java b/src/kademlia/tests/DHTContentImpl.java index dcc5368..71d0085 100644 --- a/src/kademlia/tests/DHTContentImpl.java +++ b/src/kademlia/tests/DHTContentImpl.java @@ -2,7 +2,7 @@ package kademlia.tests; import com.google.gson.Gson; import kademlia.dht.KadContent; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * A simple DHT Content object to test DHT storage @@ -15,7 +15,7 @@ public class DHTContentImpl implements KadContent public static final transient String TYPE = "DHTContentImpl"; - private NodeId key; + private KademliaId key; private String data; private String ownerId; private final long createTs; @@ -35,10 +35,10 @@ public class DHTContentImpl implements KadContent { this.ownerId = ownerId; this.data = data; - this.key = new NodeId(); + this.key = new KademliaId(); } - public DHTContentImpl(NodeId key, String ownerId) + public DHTContentImpl(KademliaId key, String ownerId) { this.key = key; this.ownerId = ownerId; @@ -51,7 +51,7 @@ public class DHTContentImpl implements KadContent } @Override - public NodeId getKey() + public KademliaId getKey() { return this.key; } diff --git a/src/kademlia/tests/NodeConnectionTest.java b/src/kademlia/tests/NodeConnectionTest.java index a946979..fc7a25a 100644 --- a/src/kademlia/tests/NodeConnectionTest.java +++ b/src/kademlia/tests/NodeConnectionTest.java @@ -2,7 +2,7 @@ package kademlia.tests; import java.io.IOException; import kademlia.KademliaNode; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * Testing connecting 2 nodes to each other @@ -18,10 +18,10 @@ public class NodeConnectionTest try { /* Setting up 2 Kad networks */ - KademliaNode kad1 = new KademliaNode("JoshuaK", new NodeId("ASF45678947584567467"), 7574); + KademliaNode kad1 = new KademliaNode("JoshuaK", new KademliaId("ASF45678947584567467"), 7574); System.out.println("Created Node Kad 1: " + kad1.getNode().getNodeId()); - KademliaNode kad2 = new KademliaNode("Crystal", new NodeId("ASERTKJDHGVHERJHGFLK"), 7572); + KademliaNode kad2 = new KademliaNode("Crystal", new KademliaId("ASERTKJDHGVHERJHGFLK"), 7572); //NodeId diff12 = kad1.getNode().getNodeId().xor(kad2.getNode().getNodeId()); System.out.println("Created Node Kad 2: " + kad2.getNode().getNodeId()); // System.out.println(kad1.getNode().getNodeId() + " ^ " + kad2.getNode().getNodeId() + " = " + diff12); @@ -37,7 +37,7 @@ public class NodeConnectionTest // System.out.println(kad2.getNode().getRoutingTable()); /* Creating a new node 3 and connecting it to 1, hoping it'll get onto 2 also */ - KademliaNode kad3 = new KademliaNode("Jessica", new NodeId("ASERTKJDOLKMNBVFR45G"), 7783); + KademliaNode kad3 = new KademliaNode("Jessica", new KademliaId("ASERTKJDOLKMNBVFR45G"), 7783); System.out.println("\n\n\n\n\n\nCreated Node Kad 3: " + kad3.getNode().getNodeId()); System.out.println("Connecting Kad 3 and Kad 2"); @@ -47,7 +47,7 @@ public class NodeConnectionTest // NodeId diff31 = kad1.getNode().getNodeId().xor(kad3.getNode().getNodeId()); // System.out.println("Kad 3 - Kad 1 distance: " + diff31.getFirstSetBitIndex()); // System.out.println("Kad 3 - Kad 2 distance: " + diff32.getFirstSetBitIndex()); - KademliaNode kad4 = new KademliaNode("Sandy", new NodeId("ASERTK85OLKMN85FR4SS"), 7789); + KademliaNode kad4 = new KademliaNode("Sandy", new KademliaId("ASERTK85OLKMN85FR4SS"), 7789); System.out.println("\n\n\n\n\n\nCreated Node Kad 4: " + kad4.getNode().getNodeId()); System.out.println("Connecting Kad 4 and Kad 2"); diff --git a/src/kademlia/tests/RefreshOperationTest.java b/src/kademlia/tests/RefreshOperationTest.java index 44ac406..5044403 100644 --- a/src/kademlia/tests/RefreshOperationTest.java +++ b/src/kademlia/tests/RefreshOperationTest.java @@ -5,7 +5,7 @@ import kademlia.dht.GetParameter; import kademlia.KademliaNode; import kademlia.dht.StorageEntry; import kademlia.exceptions.ContentNotFoundException; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * Testing sending and receiving content between 2 Nodes on a network @@ -21,8 +21,8 @@ public class RefreshOperationTest try { /* Setting up 2 Kad networks */ - KademliaNode kad1 = new KademliaNode("JoshuaK", new NodeId("ASF45678947584567467"), 7574); - KademliaNode kad2 = new KademliaNode("Crystal", new NodeId("ASERTKJDHGVHERJHGFLK"), 7572); + KademliaNode kad1 = new KademliaNode("JoshuaK", new KademliaId("ASF45678947584567467"), 7574); + KademliaNode kad2 = new KademliaNode("Crystal", new KademliaId("ASERTKJDHGVHERJHGFLK"), 7572); kad2.bootstrap(kad1.getNode()); /* Lets create the content and share it */ diff --git a/src/kademlia/tests/RoutingTableSimulation.java b/src/kademlia/tests/RoutingTableSimulation.java index 63b0cf6..90858bc 100644 --- a/src/kademlia/tests/RoutingTableSimulation.java +++ b/src/kademlia/tests/RoutingTableSimulation.java @@ -1,7 +1,7 @@ package kademlia.tests; import kademlia.KademliaNode; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; import kademlia.routing.RoutingTable; /** @@ -18,11 +18,11 @@ public class RoutingTableSimulation try { /* Setting up 2 Kad networks */ - KademliaNode kad1 = new KademliaNode("JoshuaK", new NodeId("ASF45678947584567463"), 12049); - KademliaNode kad2 = new KademliaNode("Crystal", new NodeId("ASF45678947584567464"), 4585); - KademliaNode kad3 = new KademliaNode("Shameer", new NodeId("ASF45678947584567465"), 8104); - KademliaNode kad4 = new KademliaNode("Lokesh", new NodeId("ASF45678947584567466"), 8335); - KademliaNode kad5 = new KademliaNode("Chandu", new NodeId("ASF45678947584567467"), 13345); + KademliaNode kad1 = new KademliaNode("JoshuaK", new KademliaId("ASF45678947584567463"), 12049); + KademliaNode kad2 = new KademliaNode("Crystal", new KademliaId("ASF45678947584567464"), 4585); + KademliaNode kad3 = new KademliaNode("Shameer", new KademliaId("ASF45678947584567465"), 8104); + KademliaNode kad4 = new KademliaNode("Lokesh", new KademliaId("ASF45678947584567466"), 8335); + KademliaNode kad5 = new KademliaNode("Chandu", new KademliaId("ASF45678947584567467"), 13345); RoutingTable rt = kad1.getRoutingTable(); diff --git a/src/kademlia/tests/RoutingTableStateTesting.java b/src/kademlia/tests/RoutingTableStateTesting.java index 9a38480..6dd0ee2 100644 --- a/src/kademlia/tests/RoutingTableStateTesting.java +++ b/src/kademlia/tests/RoutingTableStateTesting.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.util.Scanner; import kademlia.KademliaNode; import kademlia.dht.KadContent; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * Testing how the routing table works and it's state after different operations @@ -26,16 +26,16 @@ public class RoutingTableStateTesting /* Setting up Kad networks */ kads = new KademliaNode[numKads]; - kads[0] = new KademliaNode("user0", new NodeId("HRF456789SD584567460"), 1334); - kads[1] = new KademliaNode("user1", new NodeId("ASF456789475DS567461"), 1209); - kads[2] = new KademliaNode("user2", new NodeId("AFG45678947584567462"), 4585); - kads[3] = new KademliaNode("user3", new NodeId("FSF45J38947584567463"), 8104); - kads[4] = new KademliaNode("user4", new NodeId("ASF45678947584567464"), 8335); - kads[5] = new KademliaNode("user5", new NodeId("GHF4567894DR84567465"), 13345); - kads[6] = new KademliaNode("user6", new NodeId("ASF45678947584567466"), 12049); - kads[7] = new KademliaNode("user7", new NodeId("AE345678947584567467"), 14585); - kads[8] = new KademliaNode("user8", new NodeId("ASAA5678947584567468"), 18104); - kads[9] = new KademliaNode("user9", new NodeId("ASF456789475845674U9"), 18335); + kads[0] = new KademliaNode("user0", new KademliaId("HRF456789SD584567460"), 1334); + kads[1] = new KademliaNode("user1", new KademliaId("ASF456789475DS567461"), 1209); + kads[2] = new KademliaNode("user2", new KademliaId("AFG45678947584567462"), 4585); + kads[3] = new KademliaNode("user3", new KademliaId("FSF45J38947584567463"), 8104); + kads[4] = new KademliaNode("user4", new KademliaId("ASF45678947584567464"), 8335); + kads[5] = new KademliaNode("user5", new KademliaId("GHF4567894DR84567465"), 13345); + kads[6] = new KademliaNode("user6", new KademliaId("ASF45678947584567466"), 12049); + kads[7] = new KademliaNode("user7", new KademliaId("AE345678947584567467"), 14585); + kads[8] = new KademliaNode("user8", new KademliaId("ASAA5678947584567468"), 18104); + kads[9] = new KademliaNode("user9", new KademliaId("ASF456789475845674U9"), 18335); for (int i = 1; i < numKads; i++) { diff --git a/src/kademlia/tests/SaveStateTest.java b/src/kademlia/tests/SaveStateTest.java index 7fb9bd0..1b46593 100644 --- a/src/kademlia/tests/SaveStateTest.java +++ b/src/kademlia/tests/SaveStateTest.java @@ -1,7 +1,7 @@ package kademlia.tests; import kademlia.KademliaNode; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * Testing the save and retrieve state operations @@ -17,11 +17,11 @@ public class SaveStateTest try { /* Setting up 2 Kad networks */ - KademliaNode kad1 = new KademliaNode("JoshuaK", new NodeId("ASF45678947584567463"), 12049); - KademliaNode kad2 = new KademliaNode("Crystal", new NodeId("ASF45678947584567464"), 4585); - KademliaNode kad3 = new KademliaNode("Shameer", new NodeId("ASF45678947584567465"), 8104); - KademliaNode kad4 = new KademliaNode("Lokesh", new NodeId("ASF45678947584567466"), 8335); - KademliaNode kad5 = new KademliaNode("Chandu", new NodeId("ASF45678947584567467"), 13345); + KademliaNode kad1 = new KademliaNode("JoshuaK", new KademliaId("ASF45678947584567463"), 12049); + KademliaNode kad2 = new KademliaNode("Crystal", new KademliaId("ASF45678947584567464"), 4585); + KademliaNode kad3 = new KademliaNode("Shameer", new KademliaId("ASF45678947584567465"), 8104); + KademliaNode kad4 = new KademliaNode("Lokesh", new KademliaId("ASF45678947584567466"), 8335); + KademliaNode kad5 = new KademliaNode("Chandu", new KademliaId("ASF45678947584567467"), 13345); /* Connecting 2 to 1 */ System.out.println("Connecting Nodes 1 & 2"); diff --git a/src/kademlia/tests/SaveStateTest2.java b/src/kademlia/tests/SaveStateTest2.java index 85f46fa..a013070 100644 --- a/src/kademlia/tests/SaveStateTest2.java +++ b/src/kademlia/tests/SaveStateTest2.java @@ -3,7 +3,7 @@ package kademlia.tests; import kademlia.KademliaNode; import kademlia.dht.GetParameter; import kademlia.dht.StorageEntry; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; /** * Testing the save and retrieve state operations. @@ -20,8 +20,8 @@ public class SaveStateTest2 try { /* Setting up 2 Kad networks */ - KademliaNode kad1 = new KademliaNode("JoshuaK", new NodeId("ASF45678947584567463"), 12049); - KademliaNode kad2 = new KademliaNode("Crystal", new NodeId("ASF45678947584567464"), 4585); + KademliaNode kad1 = new KademliaNode("JoshuaK", new KademliaId("ASF45678947584567463"), 12049); + KademliaNode kad2 = new KademliaNode("Crystal", new KademliaId("ASF45678947584567464"), 4585); /* Connecting 2 to 1 */ System.out.println("Connecting Nodes 1 & 2"); diff --git a/src/kademlia/tests/SimpleMessageTest.java b/src/kademlia/tests/SimpleMessageTest.java index 71f35ca..7ba24b9 100644 --- a/src/kademlia/tests/SimpleMessageTest.java +++ b/src/kademlia/tests/SimpleMessageTest.java @@ -3,7 +3,7 @@ package kademlia.tests; import java.io.IOException; import kademlia.KademliaNode; import kademlia.message.SimpleMessage; -import kademlia.node.NodeId; +import kademlia.node.KademliaId; import kademlia.message.SimpleReceiver; /** @@ -19,8 +19,8 @@ public class SimpleMessageTest { try { - KademliaNode kad1 = new KademliaNode("Joshua", new NodeId("12345678901234567890"), 7574); - KademliaNode kad2 = new KademliaNode("Crystal", new NodeId("12345678901234567891"), 7572); + KademliaNode kad1 = new KademliaNode("Joshua", new KademliaId("12345678901234567890"), 7574); + KademliaNode kad2 = new KademliaNode("Crystal", new KademliaId("12345678901234567891"), 7572); kad1.getServer().sendMessage(kad2.getNode(), new SimpleMessage("Some Message"), new SimpleReceiver()); }