From cc1d03ba8191c06e09d31367cd789f63adf30dc9 Mon Sep 17 00:00:00 2001 From: Joshua Kissoon Date: Wed, 2 Apr 2014 18:39:16 +0530 Subject: [PATCH] Some comments and fixes --- src/kademlia/dht/KadContent.java | 20 +++++++++++++++++--- src/kademlia/tests/ContentSendingTest.java | 1 - src/kademlia/tests/DHTContentImpl.java | 11 ++++++----- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/kademlia/dht/KadContent.java b/src/kademlia/dht/KadContent.java index 3033fba..ff15f9c 100644 --- a/src/kademlia/dht/KadContent.java +++ b/src/kademlia/dht/KadContent.java @@ -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 * * @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); } diff --git a/src/kademlia/tests/ContentSendingTest.java b/src/kademlia/tests/ContentSendingTest.java index 0230b54..b9f75c8 100644 --- a/src/kademlia/tests/ContentSendingTest.java +++ b/src/kademlia/tests/ContentSendingTest.java @@ -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 conte = kad2.get(gp, 4); diff --git a/src/kademlia/tests/DHTContentImpl.java b/src/kademlia/tests/DHTContentImpl.java index 0ef3b60..46166e8 100644 --- a/src/kademlia/tests/DHTContentImpl.java +++ b/src/kademlia/tests/DHTContentImpl.java @@ -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) {