Continuing work on message sending

This commit is contained in:
Joshua Kissoon 2014-02-25 13:42:08 +05:30
parent faef3d03ec
commit 995da2cffb
8 changed files with 68 additions and 15 deletions

View File

@ -119,6 +119,10 @@ public class KadServer
private void sendMessage(Node to, Message msg, int comm) throws IOException
{
final Class<?> clazz = msg.getClass();
System.out.println(clazz.getSimpleName());
System.out.println(clazz);
/* Setup the message for transmission */
ByteArrayOutputStream bout = new ByteArrayOutputStream();

View File

@ -4,7 +4,7 @@ import java.io.IOException;
import java.net.InetAddress;
import java.util.Timer;
import java.util.TimerTask;
import kademlia.dht.DHTContent;
import kademlia.dht.KadContent;
import kademlia.exceptions.RoutingException;
import kademlia.message.MessageFactory;
import kademlia.node.Node;
@ -125,7 +125,7 @@ public class Kademlia
* @throws java.io.IOException
*
*/
public int put(DHTContent content) throws IOException
public int put(KadContent content) throws IOException
{
return (int) new StoreOperation(server, localNode, content).execute();
}
@ -139,7 +139,7 @@ public class Kademlia
*
* @return DHTContent The content
*/
public DHTContent get(GetParameter param, Class c)
public KadContent get(GetParameter param, Class c)
{
return null;
}

View File

@ -8,7 +8,7 @@ import kademlia.node.NodeId;
* @author Joshua Kissoon
* @since 20140224
*/
public interface DHTContent
public interface KadContent
{
/**

View File

@ -2,7 +2,7 @@ package kademlia.message;
import java.io.DataInput;
import java.io.DataOutput;
import kademlia.dht.DHTContent;
import kademlia.dht.KadContent;
import kademlia.node.Node;
/**
@ -15,7 +15,7 @@ public class ContentStoreMessage implements Message
{
private final Node origin;
private final DHTContent content;
private final KadContent content;
public final static byte CODE = 0x23;
@ -23,7 +23,7 @@ public class ContentStoreMessage implements Message
* @param origin Where did this content come from - it'll always be the local node
* @param content The Content to send
*/
public ContentStoreMessage(Node origin, DHTContent content)
public ContentStoreMessage(Node origin, KadContent content)
{
this.origin = origin;
this.content = content;
@ -52,7 +52,7 @@ public class ContentStoreMessage implements Message
return this.origin;
}
public DHTContent getContent()
public KadContent getContent()
{
return this.content;
}

View File

@ -3,7 +3,7 @@ package kademlia.operation;
import java.io.IOException;
import java.util.ArrayList;
import kademlia.core.KadServer;
import kademlia.dht.DHTContent;
import kademlia.dht.KadContent;
import kademlia.node.Node;
/**
@ -17,14 +17,14 @@ public class StoreOperation implements Operation
private final KadServer server;
private final Node localNode;
private final DHTContent content;
private final KadContent content;
/**
* @param server
* @param localNode
* @param content The content to be stored on the DHT
*/
public StoreOperation(KadServer server, Node localNode, DHTContent content)
public StoreOperation(KadServer server, Node localNode, KadContent content)
{
this.server = server;
this.localNode = localNode;
@ -36,6 +36,9 @@ public class StoreOperation implements Operation
{
/* Get the nodes on which we need to store the content */
ArrayList<Node> nodes = new NodeLookupOperation(this.server, this.localNode, this.content.getKey()).execute();
System.out.println("Nodes to put content on: " + nodes);
/* Return how many nodes the content was stored on */

View File

@ -0,0 +1,12 @@
package kademlia.serializer;
/**
* A KadContentSerializer that serializes content to JSON format
*
* @author Joshua Kissoon
* @since 20140225
*/
public class JsonSerializer implements KadContentSerializer
{
}

View File

@ -0,0 +1,34 @@
package kademlia.serializer;
import java.io.DataInput;
import java.io.DataOutput;
import kademlia.dht.KadContent;
/**
* A Serializer is used to transform data to and from a specified form.
*
* Here we define the structure of any Serializer used in Kademlia
*
* @author Joshua Kissoon
* @since 20140225
*/
public interface KadContentSerializer
{
/**
* Write a KadContent to a DataOutput stream
*
* @param content The content to write
* @param out The output Stream to write to
*/
public void write(KadContent content, DataOutput out);
/**
* Read a KadContent from a DataInput Stream
*
* @param in The InputStream to read the data from
*
* @return KadContent
*/
public KadContent read(DataInput in);
}

View File

@ -1,6 +1,6 @@
package kademlia.tests;
import kademlia.dht.DHTContent;
import kademlia.dht.KadContent;
import kademlia.node.NodeId;
/**
@ -9,7 +9,7 @@ import kademlia.node.NodeId;
* @author Joshua Kissoon
* @since 20140224
*/
public class DHTContentImpl implements DHTContent
public class DHTContentImpl implements KadContent
{
private final NodeId key;