Renamed the KadRoutingTable to KademliaRoutingTable

Renamed RoutingTable to JKademliaRoutingTable because it's an implementation of KademliaRoutingTable
This commit is contained in:
Joshua Kissoon 2014-05-23 20:51:28 +05:30
parent 66616a7afd
commit 41df450f4a
7 changed files with 39 additions and 39 deletions

View File

@ -25,7 +25,7 @@ import kademlia.operation.ContentLookupOperation;
import kademlia.operation.Operation;
import kademlia.operation.KadRefreshOperation;
import kademlia.operation.StoreOperation;
import kademlia.routing.RoutingTable;
import kademlia.routing.JKademliaRoutingTable;
import kademlia.util.serializer.JsonDHTSerializer;
import kademlia.util.serializer.JsonRoutingTableSerializer;
import kademlia.util.serializer.JsonSerializer;
@ -50,7 +50,7 @@ public class JKademliaNode implements KademliaNode
private final transient Node localNode;
private final transient KadServer server;
private final transient DHT dht;
private transient RoutingTable routingTable;
private transient JKademliaRoutingTable routingTable;
private final int udpPort;
private transient KadConfiguration config;
@ -86,7 +86,7 @@ public class JKademliaNode implements KademliaNode
* from disk <i>or</i> a network error occurred while
* attempting to bootstrap to the network
* */
public JKademliaNode(String ownerId, Node localNode, int udpPort, DHT dht, RoutingTable routingTable, KadConfiguration config) throws IOException
public JKademliaNode(String ownerId, Node localNode, int udpPort, DHT dht, JKademliaRoutingTable routingTable, KadConfiguration config) throws IOException
{
this.ownerId = ownerId;
this.udpPort = udpPort;
@ -131,7 +131,7 @@ public class JKademliaNode implements KademliaNode
this.refreshOperationTimer.purge();
}
public JKademliaNode(String ownerId, Node node, int udpPort, RoutingTable routingTable, KadConfiguration config) throws IOException
public JKademliaNode(String ownerId, Node node, int udpPort, JKademliaRoutingTable routingTable, KadConfiguration config) throws IOException
{
this(
ownerId,
@ -149,7 +149,7 @@ public class JKademliaNode implements KademliaNode
ownerId,
node,
udpPort,
new RoutingTable(node, config),
new JKademliaRoutingTable(node, config),
config
);
}
@ -204,7 +204,7 @@ public class JKademliaNode implements KademliaNode
* @section Read the routing table
*/
din = new DataInputStream(new FileInputStream(getStateStorageFolderName(ownerId, iconfig) + File.separator + "routingtable.kns"));
RoutingTable irtbl = new JsonRoutingTableSerializer(iconfig).read(din);
JKademliaRoutingTable irtbl = new JsonRoutingTableSerializer(iconfig).read(din);
/**
* @section Read the node state
@ -381,7 +381,7 @@ public class JKademliaNode implements KademliaNode
}
@Override
public RoutingTable getRoutingTable()
public JKademliaRoutingTable getRoutingTable()
{
return this.routingTable;
}

View File

@ -9,7 +9,7 @@ import kademlia.dht.StorageEntry;
import kademlia.exceptions.ContentNotFoundException;
import kademlia.exceptions.RoutingException;
import kademlia.node.Node;
import kademlia.routing.RoutingTable;
import kademlia.routing.JKademliaRoutingTable;
/**
* The main Kademlia Node on the network, this node manages everything for this local system.
@ -145,7 +145,7 @@ public interface KademliaNode
/**
* @return The routing table for this node.
*/
public RoutingTable getRoutingTable();
public JKademliaRoutingTable getRoutingTable();
/**
* @return The statistician that manages all statistics

View File

@ -36,9 +36,9 @@ public class ContentRefreshOperation implements Operation
/**
* For each content stored on this DHT, distribute it to the K closest nodes
* Also delete the content if this node is no longer one of the K closest nodes
*
* We assume that our RoutingTable is updated, and we can get the K closest nodes from that table
Also delete the content if this node is no longer one of the K closest nodes
We assume that our JKademliaRoutingTable is updated, and we can get the K closest nodes from that table
*
* @throws java.io.IOException
*/

View File

@ -14,7 +14,7 @@ import kademlia.node.KademliaId;
* @author Joshua Kissoon
* @created 20140215
*/
public class RoutingTable implements KadRoutingTable
public class JKademliaRoutingTable implements KademliaRoutingTable
{
private final Node localNode; // The current node
@ -22,7 +22,7 @@ public class RoutingTable implements KadRoutingTable
private transient KadConfiguration config;
public RoutingTable(Node localNode, KadConfiguration config)
public JKademliaRoutingTable(Node localNode, KadConfiguration config)
{
this.localNode = localNode;
this.config = config;
@ -35,7 +35,7 @@ public class RoutingTable implements KadRoutingTable
}
/**
* Initialize the RoutingTable to it's default state
* Initialize the JKademliaRoutingTable to it's default state
*/
@Override
public final void initialize()
@ -121,7 +121,7 @@ public class RoutingTable implements KadRoutingTable
}
/**
* @return List A List of all Nodes in this RoutingTable
* @return List A List of all Nodes in this JKademliaRoutingTable
*/
@Override
public synchronized final List<Node> getAllNodes()
@ -140,7 +140,7 @@ public class RoutingTable implements KadRoutingTable
}
/**
* @return List A List of all Nodes in this RoutingTable
* @return List A List of all Nodes in this JKademliaRoutingTable
*/
@Override
public final List<Contact> getAllContacts()

View File

@ -11,7 +11,7 @@ import kademlia.node.KademliaId;
* @author Joshua Kissoon
* @since 20140501
*/
public interface KadRoutingTable
public interface KademliaRoutingTable
{
/**

View File

@ -2,7 +2,7 @@ package kademlia.simulations;
import kademlia.JKademliaNode;
import kademlia.node.KademliaId;
import kademlia.routing.RoutingTable;
import kademlia.routing.JKademliaRoutingTable;
/**
* Testing how the routing table works and checking if everything works properly
@ -24,7 +24,7 @@ public class RoutingTableSimulation
JKademliaNode kad4 = new JKademliaNode("Lokesh", new KademliaId("ASF45678947584567466"), 8335);
JKademliaNode kad5 = new JKademliaNode("Chandu", new KademliaId("ASF45678947584567467"), 13345);
RoutingTable rt = kad1.getRoutingTable();
JKademliaRoutingTable rt = kad1.getRoutingTable();
rt.insert(kad2.getNode());
rt.insert(kad3.getNode());

View File

@ -9,7 +9,7 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import kademlia.routing.RoutingTable;
import kademlia.routing.JKademliaRoutingTable;
import java.lang.reflect.Type;
import java.util.List;
import kademlia.KadConfiguration;
@ -17,13 +17,13 @@ import kademlia.routing.Contact;
/**
* A KadSerializer that serializes routing tables to JSON format
* The generic serializer is not working for routing tables
*
* Why a RoutingTable specific serializer?
* The routing table structure:
* - RoutingTable
* -- Buckets[]
* --- Map<NodeId, Node>
The generic serializer is not working for routing tables
Why a JKademliaRoutingTable specific serializer?
The routing table structure:
- JKademliaRoutingTable
-- Buckets[]
--- Map<NodeId, Node>
* ---- NodeId:KeyBytes
* ---- Node: NodeId, InetAddress, Port
*
@ -31,15 +31,15 @@ import kademlia.routing.Contact;
* especially at the Map part.
*
* Solution
* - Make the Buckets[] transient
* - Simply store all Nodes in the serialized object
* - When reloading, re-add all nodes to the RoutingTable
- Make the Buckets[] transient
- Simply store all Nodes in the serialized object
- When reloading, re-add all nodes to the JKademliaRoutingTable
*
* @author Joshua Kissoon
*
* @since 20140310
*/
public class JsonRoutingTableSerializer implements KadSerializer<RoutingTable>
public class JsonRoutingTableSerializer implements KadSerializer<JKademliaRoutingTable>
{
private final Gson gson;
@ -66,14 +66,14 @@ public class JsonRoutingTableSerializer implements KadSerializer<RoutingTable>
}
@Override
public void write(RoutingTable data, DataOutputStream out) throws IOException
public void write(JKademliaRoutingTable data, DataOutputStream out) throws IOException
{
try (JsonWriter writer = new JsonWriter(new OutputStreamWriter(out)))
{
writer.beginArray();
/* Write the basic RoutingTable */
gson.toJson(data, RoutingTable.class, writer);
/* Write the basic JKademliaRoutingTable */
gson.toJson(data, JKademliaRoutingTable.class, writer);
/* Now Store the Contacts */
gson.toJson(data.getAllContacts(), contactCollectionType, writer);
@ -83,18 +83,18 @@ public class JsonRoutingTableSerializer implements KadSerializer<RoutingTable>
}
@Override
public RoutingTable read(DataInputStream in) throws IOException, ClassNotFoundException
public JKademliaRoutingTable read(DataInputStream in) throws IOException, ClassNotFoundException
{
try (DataInputStream din = new DataInputStream(in);
JsonReader reader = new JsonReader(new InputStreamReader(in)))
{
reader.beginArray();
/* Read the basic RoutingTable */
RoutingTable tbl = gson.fromJson(reader, RoutingTable.class);
/* Read the basic JKademliaRoutingTable */
JKademliaRoutingTable tbl = gson.fromJson(reader, JKademliaRoutingTable.class);
tbl.setConfiguration(config);
/* Now get the Contacts and add them back to the RoutingTable */
/* Now get the Contacts and add them back to the JKademliaRoutingTable */
List<Contact> contacts = gson.fromJson(reader, contactCollectionType);
tbl.initialize();