Some comments and fixes

This commit is contained in:
Joshua Kissoon 2014-04-02 18:39:16 +05:30
parent 3e236f4d17
commit cc1d03ba81
3 changed files with 23 additions and 9 deletions

View File

@ -1,19 +1,17 @@
package kademlia.dht;
import com.google.gson.Gson;
import kademlia.node.NodeId;
/**
* Any piece of content that needs to be stored on the DHT
*
* @author Joshua Kissoon
* @param <T>
*
* @since 20140224
*/
public interface KadContent
{
/**
* @return NodeId The DHT key for this content
*/
@ -45,7 +43,23 @@ public interface KadContent
*/
public String getOwnerId();
/**
* Each content needs to be in byte format for transporting and storage,
* this method takes care of that.
*
* Each object is responsible for transforming itself to byte format since the
* structure of methods may differ.
*
* @return byte[] The content in byte format
*/
public byte[] toBytes();
/**
* Given the Content in byte format, read it
*
* @param data The object in byte format
*
* @return A new object from the given byte[]
*/
public KadContent fromBytes(byte[] data);
}

View File

@ -38,7 +38,6 @@ public class ContentSendingTest
*/
System.out.println("Retrieving Content");
GetParameter gp = new GetParameter(c.getKey(), DHTContentImpl.TYPE);
gp.setType(DHTContentImpl.TYPE);
gp.setOwnerId(c.getOwnerId());
System.out.println("Get Parameter: " + gp);
List<StorageEntry> conte = kad2.get(gp, 4);

View File

@ -13,6 +13,8 @@ import kademlia.node.NodeId;
public class DHTContentImpl implements KadContent
{
public static final transient String TYPE = "DHTContentImpl";
private NodeId key;
private String data;
private String ownerId;
@ -22,10 +24,10 @@ public class DHTContentImpl implements KadContent
{
this.createTs = this.updateTs = System.currentTimeMillis() / 1000L;
}
public DHTContentImpl()
{
}
public DHTContentImpl(String ownerId, String data)
@ -75,15 +77,14 @@ public class DHTContentImpl implements KadContent
{
return this.updateTs;
}
@Override
public byte[] toBytes()
{
Gson gson = new Gson();
return gson.toJson(this).getBytes();
}
@Override
public DHTContentImpl fromBytes(byte[] data)
{