Renamed NodeId to KademliaId Since that's basically what it is!

This commit is contained in:
Joshua Kissoon 2014-05-09 11:03:00 +05:30
parent ac950720f3
commit 3ab6b3d2ab
26 changed files with 112 additions and 112 deletions

View File

@ -22,7 +22,7 @@ import kademlia.exceptions.ContentNotFoundException;
import kademlia.exceptions.RoutingException; import kademlia.exceptions.RoutingException;
import kademlia.message.MessageFactory; import kademlia.message.MessageFactory;
import kademlia.node.Node; import kademlia.node.Node;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
import kademlia.operation.ConnectOperation; import kademlia.operation.ConnectOperation;
import kademlia.operation.ContentLookupOperation; import kademlia.operation.ContentLookupOperation;
import kademlia.operation.Operation; 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( this(
ownerId, ownerId,

View File

@ -12,7 +12,7 @@ import java.util.NoSuchElementException;
import kademlia.core.KadConfiguration; import kademlia.core.KadConfiguration;
import kademlia.exceptions.ContentExistException; import kademlia.exceptions.ContentExistException;
import kademlia.exceptions.ContentNotFoundException; import kademlia.exceptions.ContentNotFoundException;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
import kademlia.util.serializer.JsonSerializer; import kademlia.util.serializer.JsonSerializer;
import kademlia.util.serializer.KadSerializer; import kademlia.util.serializer.KadSerializer;
@ -155,7 +155,7 @@ public class DHT
* *
* @return A KadContent object * @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); String folder = this.getContentStorageFolderName(key);
DataInputStream din = new DataInputStream(new FileInputStream(folder + File.separator + hashCode + ".kct")); 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 * @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 * Each content is stored in a folder named after the first 10 characters of the NodeId

View File

@ -1,6 +1,6 @@
package kademlia.dht; package kademlia.dht;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
/** /**
* A GET request can get content based on Key, Owner, Type, etc * A GET request can get content based on Key, Owner, Type, etc
@ -15,7 +15,7 @@ import kademlia.node.NodeId;
public class GetParameter public class GetParameter
{ {
private NodeId key; private KademliaId key;
private String ownerId = null; private String ownerId = null;
private String type = null; private String type = null;
@ -25,7 +25,7 @@ public class GetParameter
* @param key * @param key
* @param type * @param type
*/ */
public GetParameter(NodeId key, String type) public GetParameter(KademliaId key, String type)
{ {
this.key = key; this.key = key;
this.type = type; this.type = type;
@ -38,7 +38,7 @@ public class GetParameter
* @param type * @param type
* @param owner * @param owner
*/ */
public GetParameter(NodeId key, String type, String owner) public GetParameter(KademliaId key, String type, String owner)
{ {
this(key, owner); this(key, owner);
this.type = type; this.type = type;
@ -84,7 +84,7 @@ public class GetParameter
} }
} }
public NodeId getKey() public KademliaId getKey()
{ {
return this.key; return this.key;
} }

View File

@ -1,6 +1,6 @@
package kademlia.dht; package kademlia.dht;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
/** /**
* Any piece of content that needs to be stored on the DHT * 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 * @return NodeId The DHT key for this content
*/ */
public NodeId getKey(); public KademliaId getKey();
/** /**
* @return String The type of content * @return String The type of content

View File

@ -1,7 +1,7 @@
package kademlia.dht; package kademlia.dht;
import java.util.Objects; import java.util.Objects;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
/** /**
* Keeps track of data for a Content stored in the DHT * Keeps track of data for a Content stored in the DHT
@ -13,7 +13,7 @@ import kademlia.node.NodeId;
public class StorageEntryMetadata public class StorageEntryMetadata
{ {
private final NodeId key; private final KademliaId key;
private final String ownerId; private final String ownerId;
private final String type; private final String type;
private final int contentHash; private final int contentHash;
@ -33,7 +33,7 @@ public class StorageEntryMetadata
this.lastRepublished = System.currentTimeMillis() / 1000L; this.lastRepublished = System.currentTimeMillis() / 1000L;
} }
public NodeId getKey() public KademliaId getKey()
{ {
return this.key; return this.key;
} }

View File

@ -7,7 +7,7 @@ import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import kademlia.exceptions.ContentExistException; import kademlia.exceptions.ContentExistException;
import kademlia.exceptions.ContentNotFoundException; 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 * 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 class StoredContentManager
{ {
private final Map<NodeId, List<StorageEntryMetadata>> entries; private final Map<KademliaId, List<StorageEntryMetadata>> entries;
{ {

View File

@ -4,7 +4,7 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import kademlia.node.Node; 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. * 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 Node origin;
private NodeId lookupId; private KademliaId lookupId;
public static final byte CODE = 0x05; 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 origin The Node from which the message is coming from
* @param lookup The key for which to lookup nodes for * @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.origin = origin;
this.lookupId = lookup; this.lookupId = lookup;
@ -41,7 +41,7 @@ public class NodeLookupMessage implements Message
public final void fromStream(DataInputStream in) throws IOException public final void fromStream(DataInputStream in) throws IOException
{ {
this.origin = new Node(in); this.origin = new Node(in);
this.lookupId = new NodeId(in); this.lookupId = new KademliaId(in);
} }
@Override @Override
@ -56,7 +56,7 @@ public class NodeLookupMessage implements Message
return this.origin; return this.origin;
} }
public NodeId getLookupId() public KademliaId getLookupId()
{ {
return this.lookupId; return this.lookupId;
} }

View File

@ -14,7 +14,7 @@ import java.util.BitSet;
import java.util.Random; import java.util.Random;
import kademlia.message.Streamable; import kademlia.message.Streamable;
public class NodeId implements Streamable public class KademliaId implements Streamable
{ {
public final transient static int ID_LENGTH = 160; public final transient static int ID_LENGTH = 160;
@ -25,7 +25,7 @@ public class NodeId implements Streamable
* *
* @param data The user generated key string * @param data The user generated key string
*/ */
public NodeId(String data) public KademliaId(String data)
{ {
keyBytes = data.getBytes(); keyBytes = data.getBytes();
if (keyBytes.length != ID_LENGTH / 8) if (keyBytes.length != ID_LENGTH / 8)
@ -37,7 +37,7 @@ public class NodeId implements Streamable
/** /**
* Generate a random key * Generate a random key
*/ */
public NodeId() public KademliaId()
{ {
keyBytes = new byte[ID_LENGTH / 8]; keyBytes = new byte[ID_LENGTH / 8];
new Random().nextBytes(keyBytes); new Random().nextBytes(keyBytes);
@ -48,7 +48,7 @@ public class NodeId implements Streamable
* *
* @param bytes * @param bytes
*/ */
public NodeId(byte[] bytes) public KademliaId(byte[] bytes)
{ {
if (bytes.length != ID_LENGTH / 8) if (bytes.length != ID_LENGTH / 8)
{ {
@ -64,7 +64,7 @@ public class NodeId implements Streamable
* *
* @throws IOException * @throws IOException
*/ */
public NodeId(DataInputStream in) throws IOException public KademliaId(DataInputStream in) throws IOException
{ {
this.fromStream(in); this.fromStream(in);
} }
@ -92,9 +92,9 @@ public class NodeId implements Streamable
@Override @Override
public boolean equals(Object o) 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 Arrays.equals(this.getBytes(), nid.getBytes());
} }
return false; return false;
@ -115,7 +115,7 @@ public class NodeId implements Streamable
* *
* @return The distance of this NodeId from the given NodeId * @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[] result = new byte[ID_LENGTH / 8];
byte[] nidBytes = nid.getBytes(); byte[] nidBytes = nid.getBytes();
@ -125,7 +125,7 @@ public class NodeId implements Streamable
result[i] = (byte) (this.keyBytes[i] ^ nidBytes[i]); result[i] = (byte) (this.keyBytes[i] ^ nidBytes[i]);
} }
NodeId resNid = new NodeId(result); KademliaId resNid = new KademliaId(result);
return resNid; return resNid;
} }
@ -137,7 +137,7 @@ public class NodeId implements Streamable
* *
* @return NodeId The newly generated NodeId * @return NodeId The newly generated NodeId
*/ */
public NodeId generateNodeIdByDistance(int distance) public KademliaId generateNodeIdByDistance(int distance)
{ {
byte[] result = new byte[ID_LENGTH / 8]; byte[] result = new byte[ID_LENGTH / 8];
@ -169,7 +169,7 @@ public class NodeId implements Streamable
result[i] = Byte.MAX_VALUE; 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 * @return Integer The distance
*/ */
public int getDistance(NodeId to) public int getDistance(KademliaId to)
{ {
/** /**
* Compute the xor of this and to * Compute the xor of this and to

View File

@ -17,7 +17,7 @@ public class KeyComparator implements Comparator<Node>
/** /**
* @param key The NodeId relative to which the distance should be measured. * @param key The NodeId relative to which the distance should be measured.
*/ */
public KeyComparator(NodeId key) public KeyComparator(KademliaId key)
{ {
this.key = key.getInt(); this.key = key.getInt();
} }

View File

@ -18,12 +18,12 @@ import kademlia.message.Streamable;
public class Node implements Streamable public class Node implements Streamable
{ {
private NodeId nodeId; private KademliaId nodeId;
private InetAddress inetAddress; private InetAddress inetAddress;
private int port; private int port;
private final String strRep; private final String strRep;
public Node(NodeId nid, InetAddress ip, int port) public Node(KademliaId nid, InetAddress ip, int port)
{ {
this.nodeId = nid; this.nodeId = nid;
this.inetAddress = ip; this.inetAddress = ip;
@ -57,7 +57,7 @@ public class Node implements Streamable
/** /**
* @return The NodeId object of this node * @return The NodeId object of this node
*/ */
public NodeId getNodeId() public KademliaId getNodeId()
{ {
return this.nodeId; return this.nodeId;
} }
@ -94,7 +94,7 @@ public class Node implements Streamable
public final void fromStream(DataInputStream in) throws IOException public final void fromStream(DataInputStream in) throws IOException
{ {
/* Load the NodeId */ /* Load the NodeId */
this.nodeId = new NodeId(in); this.nodeId = new KademliaId(in);
/* Load the IP Address */ /* Load the IP Address */
byte[] ip = new byte[4]; byte[] ip = new byte[4];

View File

@ -4,7 +4,7 @@ import java.io.IOException;
import kademlia.KademliaNode; import kademlia.KademliaNode;
import kademlia.core.KadConfiguration; import kademlia.core.KadConfiguration;
import kademlia.core.KadServer; import kademlia.core.KadServer;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
/** /**
* At each time interval t, nodes need to refresh their K-Buckets * At each time interval t, nodes need to refresh their K-Buckets
@ -40,10 +40,10 @@ public class BucketRefreshOperation implements Operation
@Override @Override
public synchronized void execute() throws IOException 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 */ /* 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 */ /* Run the Node Lookup Operation, each in a different thread to speed up things */
new Thread() new Thread()

View File

@ -17,7 +17,7 @@ import kademlia.message.NodeLookupMessage;
import kademlia.message.NodeReplyMessage; import kademlia.message.NodeReplyMessage;
import kademlia.node.KeyComparator; import kademlia.node.KeyComparator;
import kademlia.node.Node; import kademlia.node.Node;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
/** /**
* Finds the K closest nodes to a specified identifier * 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 lookupId The ID for which to find nodes close to
* @param config * @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.server = server;
this.localNode = localNode; this.localNode = localNode;

View File

@ -3,7 +3,7 @@ package kademlia.routing;
import java.util.List; import java.util.List;
import kademlia.core.KadConfiguration; import kademlia.core.KadConfiguration;
import kademlia.node.Node; import kademlia.node.Node;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
/** /**
* Specification for Kademlia's Routing Table * 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. * @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 * 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 * @return List A List of contacts closest to target
*/ */
public List<Node> findClosest(NodeId target, int numNodesRequired); public List<Node> findClosest(KademliaId target, int numNodesRequired);
/** /**
* @return List A List of all Nodes in this RoutingTable * @return List A List of all Nodes in this RoutingTable

View File

@ -6,7 +6,7 @@ import java.util.TreeSet;
import kademlia.core.KadConfiguration; import kademlia.core.KadConfiguration;
import kademlia.node.KeyComparator; import kademlia.node.KeyComparator;
import kademlia.node.Node; import kademlia.node.Node;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
/** /**
* Implementation of a Kademlia routing table * Implementation of a Kademlia routing table
@ -40,8 +40,8 @@ public class RoutingTable implements KadRoutingTable
@Override @Override
public final void initialize() public final void initialize()
{ {
this.buckets = new KadBucket[NodeId.ID_LENGTH]; this.buckets = new KadBucket[KademliaId.ID_LENGTH];
for (int i = 0; i < NodeId.ID_LENGTH; i++) for (int i = 0; i < KademliaId.ID_LENGTH; i++)
{ {
buckets[i] = new KadBucketImpl(i, this.config); 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. * @return Integer The bucket ID in which the given node should be placed.
*/ */
@Override @Override
public final int getBucketId(NodeId nid) public final int getBucketId(KademliaId nid)
{ {
int bId = this.localNode.getNodeId().getDistance(nid) - 1; 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 * @return List A List of contacts closest to target
*/ */
@Override @Override
public synchronized final List<Node> findClosest(NodeId target, int numNodesRequired) public synchronized final List<Node> findClosest(KademliaId target, int numNodesRequired)
{ {
TreeSet<Node> sortedSet = new TreeSet<>(new KeyComparator(target)); TreeSet<Node> sortedSet = new TreeSet<>(new KeyComparator(target));
sortedSet.addAll(this.getAllNodes()); sortedSet.addAll(this.getAllNodes());

View File

@ -5,7 +5,7 @@ import java.util.TimerTask;
import kademlia.core.DefaultConfiguration; import kademlia.core.DefaultConfiguration;
import kademlia.KademliaNode; import kademlia.KademliaNode;
import kademlia.core.KadConfiguration; import kademlia.core.KadConfiguration;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
/** /**
* Testing the Kademlia Auto Content and Node table refresh operations * Testing the Kademlia Auto Content and Node table refresh operations
@ -21,11 +21,11 @@ public class AutoRefreshOperationTest
try try
{ {
/* Setting up 2 Kad networks */ /* Setting up 2 Kad networks */
final KademliaNode kad1 = new KademliaNode("JoshuaK", new NodeId("ASF456789djem45674DH"), 12049); final KademliaNode kad1 = new KademliaNode("JoshuaK", new KademliaId("ASF456789djem45674DH"), 12049);
final KademliaNode kad2 = new KademliaNode("Crystal", new NodeId("AJDHR678947584567464"), 4585); final KademliaNode kad2 = new KademliaNode("Crystal", new KademliaId("AJDHR678947584567464"), 4585);
final KademliaNode kad3 = new KademliaNode("Shameer", new NodeId("AS84k6789KRNS45KFJ8W"), 8104); final KademliaNode kad3 = new KademliaNode("Shameer", new KademliaId("AS84k6789KRNS45KFJ8W"), 8104);
final KademliaNode kad4 = new KademliaNode("Lokesh.", new NodeId("ASF45678947A845674GG"), 8335); final KademliaNode kad4 = new KademliaNode("Lokesh.", new KademliaId("ASF45678947A845674GG"), 8335);
final KademliaNode kad5 = new KademliaNode("Chandu.", new NodeId("AS84kUD894758456dyrj"), 13345); final KademliaNode kad5 = new KademliaNode("Chandu.", new KademliaId("AS84kUD894758456dyrj"), 13345);
/* Connecting nodes */ /* Connecting nodes */
System.out.println("Connecting Nodes"); System.out.println("Connecting Nodes");
@ -34,7 +34,7 @@ public class AutoRefreshOperationTest
kad4.bootstrap(kad2.getNode()); kad4.bootstrap(kad2.getNode());
kad5.bootstrap(kad4.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"); c.setData("Setting the data");
System.out.println("\n Content ID: " + c.getKey()); System.out.println("\n Content ID: " + c.getKey());

View File

@ -5,7 +5,7 @@ import java.util.TimerTask;
import kademlia.core.DefaultConfiguration; import kademlia.core.DefaultConfiguration;
import kademlia.KademliaNode; import kademlia.KademliaNode;
import kademlia.core.KadConfiguration; import kademlia.core.KadConfiguration;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
/** /**
* Testing the Kademlia Auto Content and Node table refresh operations * Testing the Kademlia Auto Content and Node table refresh operations
@ -21,16 +21,16 @@ public class AutoRefreshOperationTest2
try try
{ {
/* Setting up 2 Kad networks */ /* Setting up 2 Kad networks */
final KademliaNode kad1 = new KademliaNode("JoshuaK", new NodeId("ASF456789djem4567463"), 12049); final KademliaNode kad1 = new KademliaNode("JoshuaK", new KademliaId("ASF456789djem4567463"), 12049);
final KademliaNode kad2 = new KademliaNode("Crystal", new NodeId("AS84k678DJRW84567465"), 4585); final KademliaNode kad2 = new KademliaNode("Crystal", new KademliaId("AS84k678DJRW84567465"), 4585);
final KademliaNode kad3 = new KademliaNode("Shameer", new NodeId("AS84k67894758456746A"), 8104); final KademliaNode kad3 = new KademliaNode("Shameer", new KademliaId("AS84k67894758456746A"), 8104);
/* Connecting nodes */ /* Connecting nodes */
System.out.println("Connecting Nodes"); System.out.println("Connecting Nodes");
kad2.bootstrap(kad1.getNode()); kad2.bootstrap(kad1.getNode());
kad3.bootstrap(kad2.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"); c.setData("Setting the data");
kad1.putLocally(c); kad1.putLocally(c);

View File

@ -5,7 +5,7 @@ import kademlia.dht.GetParameter;
import kademlia.KademliaNode; import kademlia.KademliaNode;
import kademlia.dht.StorageEntry; import kademlia.dht.StorageEntry;
import kademlia.exceptions.ContentNotFoundException; import kademlia.exceptions.ContentNotFoundException;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
/** /**
* Testing sending and receiving content between 2 Nodes on a network * Testing sending and receiving content between 2 Nodes on a network
@ -21,9 +21,9 @@ public class ContentSendingTest
try try
{ {
/* Setting up 2 Kad networks */ /* 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()); 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()); System.out.println("Created Node Kad 2: " + kad2.getNode().getNodeId());
kad2.bootstrap(kad1.getNode()); kad2.bootstrap(kad1.getNode());

View File

@ -5,7 +5,7 @@ import kademlia.dht.GetParameter;
import kademlia.KademliaNode; import kademlia.KademliaNode;
import kademlia.dht.StorageEntry; import kademlia.dht.StorageEntry;
import kademlia.exceptions.ContentNotFoundException; import kademlia.exceptions.ContentNotFoundException;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
/** /**
* Testing sending and receiving content between 2 Nodes on a network * Testing sending and receiving content between 2 Nodes on a network
@ -21,9 +21,9 @@ public class ContentUpdatingTest
try try
{ {
/* Setting up 2 Kad networks */ /* 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()); 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()); System.out.println("Created Node Kad 2: " + kad2.getNode().getNodeId());
kad2.bootstrap(kad1.getNode()); kad2.bootstrap(kad1.getNode());

View File

@ -2,7 +2,7 @@ package kademlia.tests;
import com.google.gson.Gson; import com.google.gson.Gson;
import kademlia.dht.KadContent; import kademlia.dht.KadContent;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
/** /**
* A simple DHT Content object to test DHT storage * 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"; public static final transient String TYPE = "DHTContentImpl";
private NodeId key; private KademliaId key;
private String data; private String data;
private String ownerId; private String ownerId;
private final long createTs; private final long createTs;
@ -35,10 +35,10 @@ public class DHTContentImpl implements KadContent
{ {
this.ownerId = ownerId; this.ownerId = ownerId;
this.data = data; 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.key = key;
this.ownerId = ownerId; this.ownerId = ownerId;
@ -51,7 +51,7 @@ public class DHTContentImpl implements KadContent
} }
@Override @Override
public NodeId getKey() public KademliaId getKey()
{ {
return this.key; return this.key;
} }

View File

@ -2,7 +2,7 @@ package kademlia.tests;
import java.io.IOException; import java.io.IOException;
import kademlia.KademliaNode; import kademlia.KademliaNode;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
/** /**
* Testing connecting 2 nodes to each other * Testing connecting 2 nodes to each other
@ -18,10 +18,10 @@ public class NodeConnectionTest
try try
{ {
/* Setting up 2 Kad networks */ /* 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()); 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()); //NodeId diff12 = kad1.getNode().getNodeId().xor(kad2.getNode().getNodeId());
System.out.println("Created Node Kad 2: " + kad2.getNode().getNodeId()); System.out.println("Created Node Kad 2: " + kad2.getNode().getNodeId());
// System.out.println(kad1.getNode().getNodeId() + " ^ " + kad2.getNode().getNodeId() + " = " + diff12); // System.out.println(kad1.getNode().getNodeId() + " ^ " + kad2.getNode().getNodeId() + " = " + diff12);
@ -37,7 +37,7 @@ public class NodeConnectionTest
// System.out.println(kad2.getNode().getRoutingTable()); // System.out.println(kad2.getNode().getRoutingTable());
/* Creating a new node 3 and connecting it to 1, hoping it'll get onto 2 also */ /* 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("\n\n\n\n\n\nCreated Node Kad 3: " + kad3.getNode().getNodeId());
System.out.println("Connecting Kad 3 and Kad 2"); 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()); // 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 1 distance: " + diff31.getFirstSetBitIndex());
// System.out.println("Kad 3 - Kad 2 distance: " + diff32.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("\n\n\n\n\n\nCreated Node Kad 4: " + kad4.getNode().getNodeId());
System.out.println("Connecting Kad 4 and Kad 2"); System.out.println("Connecting Kad 4 and Kad 2");

View File

@ -5,7 +5,7 @@ import kademlia.dht.GetParameter;
import kademlia.KademliaNode; import kademlia.KademliaNode;
import kademlia.dht.StorageEntry; import kademlia.dht.StorageEntry;
import kademlia.exceptions.ContentNotFoundException; import kademlia.exceptions.ContentNotFoundException;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
/** /**
* Testing sending and receiving content between 2 Nodes on a network * Testing sending and receiving content between 2 Nodes on a network
@ -21,8 +21,8 @@ public class RefreshOperationTest
try try
{ {
/* Setting up 2 Kad networks */ /* Setting up 2 Kad networks */
KademliaNode kad1 = new KademliaNode("JoshuaK", new NodeId("ASF45678947584567467"), 7574); KademliaNode kad1 = new KademliaNode("JoshuaK", new KademliaId("ASF45678947584567467"), 7574);
KademliaNode kad2 = new KademliaNode("Crystal", new NodeId("ASERTKJDHGVHERJHGFLK"), 7572); KademliaNode kad2 = new KademliaNode("Crystal", new KademliaId("ASERTKJDHGVHERJHGFLK"), 7572);
kad2.bootstrap(kad1.getNode()); kad2.bootstrap(kad1.getNode());
/* Lets create the content and share it */ /* Lets create the content and share it */

View File

@ -1,7 +1,7 @@
package kademlia.tests; package kademlia.tests;
import kademlia.KademliaNode; import kademlia.KademliaNode;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
import kademlia.routing.RoutingTable; import kademlia.routing.RoutingTable;
/** /**
@ -18,11 +18,11 @@ public class RoutingTableSimulation
try try
{ {
/* Setting up 2 Kad networks */ /* Setting up 2 Kad networks */
KademliaNode kad1 = new KademliaNode("JoshuaK", new NodeId("ASF45678947584567463"), 12049); KademliaNode kad1 = new KademliaNode("JoshuaK", new KademliaId("ASF45678947584567463"), 12049);
KademliaNode kad2 = new KademliaNode("Crystal", new NodeId("ASF45678947584567464"), 4585); KademliaNode kad2 = new KademliaNode("Crystal", new KademliaId("ASF45678947584567464"), 4585);
KademliaNode kad3 = new KademliaNode("Shameer", new NodeId("ASF45678947584567465"), 8104); KademliaNode kad3 = new KademliaNode("Shameer", new KademliaId("ASF45678947584567465"), 8104);
KademliaNode kad4 = new KademliaNode("Lokesh", new NodeId("ASF45678947584567466"), 8335); KademliaNode kad4 = new KademliaNode("Lokesh", new KademliaId("ASF45678947584567466"), 8335);
KademliaNode kad5 = new KademliaNode("Chandu", new NodeId("ASF45678947584567467"), 13345); KademliaNode kad5 = new KademliaNode("Chandu", new KademliaId("ASF45678947584567467"), 13345);
RoutingTable rt = kad1.getRoutingTable(); RoutingTable rt = kad1.getRoutingTable();

View File

@ -4,7 +4,7 @@ import java.io.IOException;
import java.util.Scanner; import java.util.Scanner;
import kademlia.KademliaNode; import kademlia.KademliaNode;
import kademlia.dht.KadContent; 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 * Testing how the routing table works and it's state after different operations
@ -26,16 +26,16 @@ public class RoutingTableStateTesting
/* Setting up Kad networks */ /* Setting up Kad networks */
kads = new KademliaNode[numKads]; kads = new KademliaNode[numKads];
kads[0] = new KademliaNode("user0", new NodeId("HRF456789SD584567460"), 1334); kads[0] = new KademliaNode("user0", new KademliaId("HRF456789SD584567460"), 1334);
kads[1] = new KademliaNode("user1", new NodeId("ASF456789475DS567461"), 1209); kads[1] = new KademliaNode("user1", new KademliaId("ASF456789475DS567461"), 1209);
kads[2] = new KademliaNode("user2", new NodeId("AFG45678947584567462"), 4585); kads[2] = new KademliaNode("user2", new KademliaId("AFG45678947584567462"), 4585);
kads[3] = new KademliaNode("user3", new NodeId("FSF45J38947584567463"), 8104); kads[3] = new KademliaNode("user3", new KademliaId("FSF45J38947584567463"), 8104);
kads[4] = new KademliaNode("user4", new NodeId("ASF45678947584567464"), 8335); kads[4] = new KademliaNode("user4", new KademliaId("ASF45678947584567464"), 8335);
kads[5] = new KademliaNode("user5", new NodeId("GHF4567894DR84567465"), 13345); kads[5] = new KademliaNode("user5", new KademliaId("GHF4567894DR84567465"), 13345);
kads[6] = new KademliaNode("user6", new NodeId("ASF45678947584567466"), 12049); kads[6] = new KademliaNode("user6", new KademliaId("ASF45678947584567466"), 12049);
kads[7] = new KademliaNode("user7", new NodeId("AE345678947584567467"), 14585); kads[7] = new KademliaNode("user7", new KademliaId("AE345678947584567467"), 14585);
kads[8] = new KademliaNode("user8", new NodeId("ASAA5678947584567468"), 18104); kads[8] = new KademliaNode("user8", new KademliaId("ASAA5678947584567468"), 18104);
kads[9] = new KademliaNode("user9", new NodeId("ASF456789475845674U9"), 18335); kads[9] = new KademliaNode("user9", new KademliaId("ASF456789475845674U9"), 18335);
for (int i = 1; i < numKads; i++) for (int i = 1; i < numKads; i++)
{ {

View File

@ -1,7 +1,7 @@
package kademlia.tests; package kademlia.tests;
import kademlia.KademliaNode; import kademlia.KademliaNode;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
/** /**
* Testing the save and retrieve state operations * Testing the save and retrieve state operations
@ -17,11 +17,11 @@ public class SaveStateTest
try try
{ {
/* Setting up 2 Kad networks */ /* Setting up 2 Kad networks */
KademliaNode kad1 = new KademliaNode("JoshuaK", new NodeId("ASF45678947584567463"), 12049); KademliaNode kad1 = new KademliaNode("JoshuaK", new KademliaId("ASF45678947584567463"), 12049);
KademliaNode kad2 = new KademliaNode("Crystal", new NodeId("ASF45678947584567464"), 4585); KademliaNode kad2 = new KademliaNode("Crystal", new KademliaId("ASF45678947584567464"), 4585);
KademliaNode kad3 = new KademliaNode("Shameer", new NodeId("ASF45678947584567465"), 8104); KademliaNode kad3 = new KademliaNode("Shameer", new KademliaId("ASF45678947584567465"), 8104);
KademliaNode kad4 = new KademliaNode("Lokesh", new NodeId("ASF45678947584567466"), 8335); KademliaNode kad4 = new KademliaNode("Lokesh", new KademliaId("ASF45678947584567466"), 8335);
KademliaNode kad5 = new KademliaNode("Chandu", new NodeId("ASF45678947584567467"), 13345); KademliaNode kad5 = new KademliaNode("Chandu", new KademliaId("ASF45678947584567467"), 13345);
/* Connecting 2 to 1 */ /* Connecting 2 to 1 */
System.out.println("Connecting Nodes 1 & 2"); System.out.println("Connecting Nodes 1 & 2");

View File

@ -3,7 +3,7 @@ package kademlia.tests;
import kademlia.KademliaNode; import kademlia.KademliaNode;
import kademlia.dht.GetParameter; import kademlia.dht.GetParameter;
import kademlia.dht.StorageEntry; import kademlia.dht.StorageEntry;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
/** /**
* Testing the save and retrieve state operations. * Testing the save and retrieve state operations.
@ -20,8 +20,8 @@ public class SaveStateTest2
try try
{ {
/* Setting up 2 Kad networks */ /* Setting up 2 Kad networks */
KademliaNode kad1 = new KademliaNode("JoshuaK", new NodeId("ASF45678947584567463"), 12049); KademliaNode kad1 = new KademliaNode("JoshuaK", new KademliaId("ASF45678947584567463"), 12049);
KademliaNode kad2 = new KademliaNode("Crystal", new NodeId("ASF45678947584567464"), 4585); KademliaNode kad2 = new KademliaNode("Crystal", new KademliaId("ASF45678947584567464"), 4585);
/* Connecting 2 to 1 */ /* Connecting 2 to 1 */
System.out.println("Connecting Nodes 1 & 2"); System.out.println("Connecting Nodes 1 & 2");

View File

@ -3,7 +3,7 @@ package kademlia.tests;
import java.io.IOException; import java.io.IOException;
import kademlia.KademliaNode; import kademlia.KademliaNode;
import kademlia.message.SimpleMessage; import kademlia.message.SimpleMessage;
import kademlia.node.NodeId; import kademlia.node.KademliaId;
import kademlia.message.SimpleReceiver; import kademlia.message.SimpleReceiver;
/** /**
@ -19,8 +19,8 @@ public class SimpleMessageTest
{ {
try try
{ {
KademliaNode kad1 = new KademliaNode("Joshua", new NodeId("12345678901234567890"), 7574); KademliaNode kad1 = new KademliaNode("Joshua", new KademliaId("12345678901234567890"), 7574);
KademliaNode kad2 = new KademliaNode("Crystal", new NodeId("12345678901234567891"), 7572); KademliaNode kad2 = new KademliaNode("Crystal", new KademliaId("12345678901234567891"), 7572);
kad1.getServer().sendMessage(kad2.getNode(), new SimpleMessage("Some Message"), new SimpleReceiver()); kad1.getServer().sendMessage(kad2.getNode(), new SimpleMessage("Some Message"), new SimpleReceiver());
} }