The entire system is changed over to use the KademliaRoutingTable class instead of the JKademliaRoutingTable implementation

This commit is contained in:
Joshua Kissoon 2014-05-23 20:56:03 +05:30
parent d6ab1493b8
commit 568f2fe9a8
4 changed files with 15 additions and 13 deletions

View File

@ -26,6 +26,7 @@ import kademlia.operation.Operation;
import kademlia.operation.KadRefreshOperation;
import kademlia.operation.StoreOperation;
import kademlia.routing.JKademliaRoutingTable;
import kademlia.routing.KademliaRoutingTable;
import kademlia.util.serializer.JsonDHTSerializer;
import kademlia.util.serializer.JsonRoutingTableSerializer;
import kademlia.util.serializer.JsonSerializer;
@ -50,7 +51,7 @@ public class JKademliaNode implements KademliaNode
private final transient Node localNode;
private final transient KadServer server;
private final transient DHT dht;
private transient JKademliaRoutingTable routingTable;
private transient KademliaRoutingTable routingTable;
private final int udpPort;
private transient KadConfiguration config;
@ -86,7 +87,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, JKademliaRoutingTable routingTable, KadConfiguration config) throws IOException
public JKademliaNode(String ownerId, Node localNode, int udpPort, DHT dht, KademliaRoutingTable routingTable, KadConfiguration config) throws IOException
{
this.ownerId = ownerId;
this.udpPort = udpPort;
@ -131,7 +132,7 @@ public class JKademliaNode implements KademliaNode
this.refreshOperationTimer.purge();
}
public JKademliaNode(String ownerId, Node node, int udpPort, JKademliaRoutingTable routingTable, KadConfiguration config) throws IOException
public JKademliaNode(String ownerId, Node node, int udpPort, KademliaRoutingTable routingTable, KadConfiguration config) throws IOException
{
this(
ownerId,
@ -204,7 +205,7 @@ public class JKademliaNode implements KademliaNode
* @section Read the routing table
*/
din = new DataInputStream(new FileInputStream(getStateStorageFolderName(ownerId, iconfig) + File.separator + "routingtable.kns"));
JKademliaRoutingTable irtbl = new JsonRoutingTableSerializer(iconfig).read(din);
KademliaRoutingTable irtbl = new JsonRoutingTableSerializer(iconfig).read(din);
/**
* @section Read the node state
@ -381,7 +382,7 @@ public class JKademliaNode implements KademliaNode
}
@Override
public JKademliaRoutingTable getRoutingTable()
public KademliaRoutingTable 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.JKademliaRoutingTable;
import kademlia.routing.KademliaRoutingTable;
/**
* 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 JKademliaRoutingTable getRoutingTable();
public KademliaRoutingTable getRoutingTable();
/**
* @return The statistician that manages all statistics

View File

@ -2,7 +2,7 @@ package kademlia.simulations;
import kademlia.JKademliaNode;
import kademlia.node.KademliaId;
import kademlia.routing.JKademliaRoutingTable;
import kademlia.routing.KademliaRoutingTable;
/**
* 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);
JKademliaRoutingTable rt = kad1.getRoutingTable();
KademliaRoutingTable rt = kad1.getRoutingTable();
rt.insert(kad2.getNode());
rt.insert(kad3.getNode());

View File

@ -14,6 +14,7 @@ import java.lang.reflect.Type;
import java.util.List;
import kademlia.KadConfiguration;
import kademlia.routing.Contact;
import kademlia.routing.KademliaRoutingTable;
/**
* A KadSerializer that serializes routing tables to JSON format
@ -39,7 +40,7 @@ import kademlia.routing.Contact;
*
* @since 20140310
*/
public class JsonRoutingTableSerializer implements KadSerializer<JKademliaRoutingTable>
public class JsonRoutingTableSerializer implements KadSerializer<KademliaRoutingTable>
{
private final Gson gson;
@ -66,7 +67,7 @@ public class JsonRoutingTableSerializer implements KadSerializer<JKademliaRoutin
}
@Override
public void write(JKademliaRoutingTable data, DataOutputStream out) throws IOException
public void write(KademliaRoutingTable data, DataOutputStream out) throws IOException
{
try (JsonWriter writer = new JsonWriter(new OutputStreamWriter(out)))
{
@ -83,7 +84,7 @@ public class JsonRoutingTableSerializer implements KadSerializer<JKademliaRoutin
}
@Override
public JKademliaRoutingTable read(DataInputStream in) throws IOException, ClassNotFoundException
public KademliaRoutingTable read(DataInputStream in) throws IOException, ClassNotFoundException
{
try (DataInputStream din = new DataInputStream(in);
JsonReader reader = new JsonReader(new InputStreamReader(in)))
@ -91,7 +92,7 @@ public class JsonRoutingTableSerializer implements KadSerializer<JKademliaRoutin
reader.beginArray();
/* Read the basic JKademliaRoutingTable */
JKademliaRoutingTable tbl = gson.fromJson(reader, JKademliaRoutingTable.class);
KademliaRoutingTable tbl = gson.fromJson(reader, KademliaRoutingTable.class);
tbl.setConfiguration(config);
/* Now get the Contacts and add them back to the JKademliaRoutingTable */