mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-11-21 17:52:21 +00:00
Switched back to using the StorageEntry class and StorageEntry Metadata class because of some issues with JSon serialization with polymorphism...
This commit is contained in:
parent
7a4cc2e91c
commit
8501740bc5
@ -266,7 +266,7 @@ public class JKademliaNode implements KademliaNode
|
||||
}
|
||||
|
||||
@Override
|
||||
public int put(KademliaStorageEntry entry) throws IOException
|
||||
public int put(JKademliaStorageEntry entry) throws IOException
|
||||
{
|
||||
StoreOperation sop = new StoreOperation(this.server, this, entry, this.dht, this.config);
|
||||
sop.execute();
|
||||
@ -282,7 +282,7 @@ public class JKademliaNode implements KademliaNode
|
||||
}
|
||||
|
||||
@Override
|
||||
public KademliaStorageEntry get(GetParameter param) throws NoSuchElementException, IOException, ContentNotFoundException
|
||||
public JKademliaStorageEntry get(GetParameter param) throws NoSuchElementException, IOException, ContentNotFoundException
|
||||
{
|
||||
if (this.dht.contains(param))
|
||||
{
|
||||
|
@ -3,6 +3,7 @@ package kademlia;
|
||||
import java.io.IOException;
|
||||
import java.util.NoSuchElementException;
|
||||
import kademlia.dht.GetParameter;
|
||||
import kademlia.dht.JKademliaStorageEntry;
|
||||
import kademlia.dht.KadContent;
|
||||
import kademlia.dht.KademliaDHT;
|
||||
import kademlia.dht.KademliaStorageEntry;
|
||||
@ -86,7 +87,7 @@ public interface KademliaNode
|
||||
* @throws java.io.IOException
|
||||
*
|
||||
*/
|
||||
public int put(KademliaStorageEntry entry) throws IOException;
|
||||
public int put(JKademliaStorageEntry entry) throws IOException;
|
||||
|
||||
/**
|
||||
* Store a content on the local node's DHT
|
||||
@ -107,7 +108,7 @@ public interface KademliaNode
|
||||
* @throws java.io.IOException
|
||||
* @throws kademlia.exceptions.ContentNotFoundException
|
||||
*/
|
||||
public KademliaStorageEntry get(GetParameter param) throws NoSuchElementException, IOException, ContentNotFoundException;
|
||||
public JKademliaStorageEntry get(GetParameter param) throws NoSuchElementException, IOException, ContentNotFoundException;
|
||||
|
||||
/**
|
||||
* Allow the user of the System to call refresh even out of the normal Kad refresh timing
|
||||
|
@ -26,7 +26,7 @@ public class DHT implements KademliaDHT
|
||||
{
|
||||
|
||||
private transient StoredContentManager contentManager;
|
||||
private transient KadSerializer<KademliaStorageEntry> serializer = null;
|
||||
private transient KadSerializer<JKademliaStorageEntry> serializer = null;
|
||||
private transient KadConfiguration config;
|
||||
|
||||
private final String ownerId;
|
||||
@ -51,7 +51,7 @@ public class DHT implements KademliaDHT
|
||||
}
|
||||
|
||||
@Override
|
||||
public KadSerializer<KademliaStorageEntry> getSerializer()
|
||||
public KadSerializer<JKademliaStorageEntry> getSerializer()
|
||||
{
|
||||
if (null == serializer)
|
||||
{
|
||||
@ -62,7 +62,7 @@ public class DHT implements KademliaDHT
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean store(KademliaStorageEntry content) throws IOException
|
||||
public boolean store(JKademliaStorageEntry content) throws IOException
|
||||
{
|
||||
/* Lets check if we have this content and it's the updated version */
|
||||
if (this.contentManager.contains(content.getContentMetadata()))
|
||||
@ -130,7 +130,7 @@ public class DHT implements KademliaDHT
|
||||
}
|
||||
|
||||
@Override
|
||||
public KademliaStorageEntry retrieve(KademliaId key, int hashCode) throws FileNotFoundException, IOException, ClassNotFoundException
|
||||
public JKademliaStorageEntry retrieve(KademliaId key, int hashCode) throws FileNotFoundException, IOException, ClassNotFoundException
|
||||
{
|
||||
String folder = this.getContentStorageFolderName(key);
|
||||
DataInputStream din = new DataInputStream(new FileInputStream(folder + File.separator + hashCode + ".kct"));
|
||||
@ -144,7 +144,7 @@ public class DHT implements KademliaDHT
|
||||
}
|
||||
|
||||
@Override
|
||||
public KademliaStorageEntry get(KademliaStorageEntryMetadata entry) throws IOException, NoSuchElementException
|
||||
public JKademliaStorageEntry get(KademliaStorageEntryMetadata entry) throws IOException, NoSuchElementException
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -164,7 +164,7 @@ public class DHT implements KademliaDHT
|
||||
}
|
||||
|
||||
@Override
|
||||
public KademliaStorageEntry get(GetParameter param) throws NoSuchElementException, IOException
|
||||
public JKademliaStorageEntry get(GetParameter param) throws NoSuchElementException, IOException
|
||||
{
|
||||
/* Load a KadContent if any exist for the given criteria */
|
||||
try
|
||||
|
@ -10,14 +10,14 @@ public class JKademliaStorageEntry implements KademliaStorageEntry
|
||||
{
|
||||
|
||||
private String content;
|
||||
private final KademliaStorageEntryMetadata metadata;
|
||||
private final StorageEntryMetadata metadata;
|
||||
|
||||
public JKademliaStorageEntry(final KadContent content)
|
||||
{
|
||||
this(content, new StorageEntryMetadata(content));
|
||||
}
|
||||
|
||||
public JKademliaStorageEntry(final KadContent content, final KademliaStorageEntryMetadata metadata)
|
||||
public JKademliaStorageEntry(final KadContent content, final StorageEntryMetadata metadata)
|
||||
{
|
||||
this.setContent(content.toSerializedForm());
|
||||
this.metadata = metadata;
|
||||
|
@ -35,7 +35,7 @@ public interface KademliaDHT
|
||||
*
|
||||
* @return The new ContentSerializer
|
||||
*/
|
||||
public KadSerializer<KademliaStorageEntry> getSerializer();
|
||||
public KadSerializer<JKademliaStorageEntry> getSerializer();
|
||||
|
||||
/**
|
||||
* Handle storing content locally
|
||||
@ -46,7 +46,7 @@ public interface KademliaDHT
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public boolean store(KademliaStorageEntry content) throws IOException;
|
||||
public boolean store(JKademliaStorageEntry content) throws IOException;
|
||||
|
||||
public boolean store(KadContent content) throws IOException;
|
||||
|
||||
@ -61,7 +61,7 @@ public interface KademliaDHT
|
||||
* @throws java.io.FileNotFoundException
|
||||
* @throws java.lang.ClassNotFoundException
|
||||
*/
|
||||
public KademliaStorageEntry retrieve(KademliaId key, int hashCode) throws FileNotFoundException, IOException, ClassNotFoundException;
|
||||
public JKademliaStorageEntry retrieve(KademliaId key, int hashCode) throws FileNotFoundException, IOException, ClassNotFoundException;
|
||||
|
||||
/**
|
||||
* Check if any content for the given criteria exists in this DHT
|
||||
@ -81,7 +81,7 @@ public interface KademliaDHT
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public KademliaStorageEntry get(KademliaStorageEntryMetadata entry) throws IOException, NoSuchElementException;
|
||||
public JKademliaStorageEntry get(KademliaStorageEntryMetadata entry) throws IOException, NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Get the StorageEntry for the content if any exist.
|
||||
@ -92,7 +92,7 @@ public interface KademliaDHT
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public KademliaStorageEntry get(GetParameter param) throws NoSuchElementException, IOException;
|
||||
public JKademliaStorageEntry get(GetParameter param) throws NoSuchElementException, IOException;
|
||||
|
||||
/**
|
||||
* Delete a content from local storage
|
||||
|
@ -3,6 +3,7 @@ package kademlia.message;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import kademlia.dht.JKademliaStorageEntry;
|
||||
import kademlia.dht.KademliaStorageEntry;
|
||||
import kademlia.node.Node;
|
||||
import kademlia.util.serializer.JsonSerializer;
|
||||
@ -18,7 +19,7 @@ public class ContentMessage implements Message
|
||||
|
||||
public static final byte CODE = 0x04;
|
||||
|
||||
private KademliaStorageEntry content;
|
||||
private JKademliaStorageEntry content;
|
||||
private Node origin;
|
||||
|
||||
/**
|
||||
@ -26,7 +27,7 @@ public class ContentMessage implements Message
|
||||
* @param content The content to be stored
|
||||
*
|
||||
*/
|
||||
public ContentMessage(Node origin, KademliaStorageEntry content)
|
||||
public ContentMessage(Node origin, JKademliaStorageEntry content)
|
||||
{
|
||||
this.content = content;
|
||||
this.origin = origin;
|
||||
@ -43,7 +44,7 @@ public class ContentMessage implements Message
|
||||
this.origin.toStream(out);
|
||||
|
||||
/* Serialize the KadContent, then send it to the stream */
|
||||
new JsonSerializer<KademliaStorageEntry>().write(content, out);
|
||||
new JsonSerializer<JKademliaStorageEntry>().write(content, out);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,7 +54,7 @@ public class ContentMessage implements Message
|
||||
|
||||
try
|
||||
{
|
||||
this.content = new JsonSerializer<KademliaStorageEntry>().read(in);
|
||||
this.content = new JsonSerializer<JKademliaStorageEntry>().read(in);
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
@ -66,7 +67,7 @@ public class ContentMessage implements Message
|
||||
return this.origin;
|
||||
}
|
||||
|
||||
public KademliaStorageEntry getContent()
|
||||
public JKademliaStorageEntry getContent()
|
||||
{
|
||||
return this.content;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package kademlia.message;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import kademlia.dht.JKademliaStorageEntry;
|
||||
import kademlia.dht.KademliaStorageEntry;
|
||||
import kademlia.node.Node;
|
||||
import kademlia.util.serializer.JsonSerializer;
|
||||
@ -18,7 +19,7 @@ public class StoreContentMessage implements Message
|
||||
|
||||
public static final byte CODE = 0x08;
|
||||
|
||||
private KademliaStorageEntry content;
|
||||
private JKademliaStorageEntry content;
|
||||
private Node origin;
|
||||
|
||||
/**
|
||||
@ -26,7 +27,7 @@ public class StoreContentMessage implements Message
|
||||
* @param content The content to be stored
|
||||
*
|
||||
*/
|
||||
public StoreContentMessage(Node origin, KademliaStorageEntry content)
|
||||
public StoreContentMessage(Node origin, JKademliaStorageEntry content)
|
||||
{
|
||||
this.content = content;
|
||||
this.origin = origin;
|
||||
@ -43,7 +44,7 @@ public class StoreContentMessage implements Message
|
||||
this.origin.toStream(out);
|
||||
|
||||
/* Serialize the KadContent, then send it to the stream */
|
||||
new JsonSerializer<KademliaStorageEntry>().write(content, out);
|
||||
new JsonSerializer<JKademliaStorageEntry>().write(content, out);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,7 +53,7 @@ public class StoreContentMessage implements Message
|
||||
this.origin = new Node(in);
|
||||
try
|
||||
{
|
||||
this.content = new JsonSerializer<KademliaStorageEntry>().read(in);
|
||||
this.content = new JsonSerializer<JKademliaStorageEntry>().read(in);
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
@ -65,7 +66,7 @@ public class StoreContentMessage implements Message
|
||||
return this.origin;
|
||||
}
|
||||
|
||||
public KademliaStorageEntry getContent()
|
||||
public JKademliaStorageEntry getContent()
|
||||
{
|
||||
return this.content;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import kademlia.JKademliaNode;
|
||||
import kademlia.dht.GetParameter;
|
||||
import kademlia.KadConfiguration;
|
||||
import kademlia.KadServer;
|
||||
import kademlia.dht.JKademliaStorageEntry;
|
||||
import kademlia.dht.KademliaStorageEntry;
|
||||
import kademlia.exceptions.ContentNotFoundException;
|
||||
import kademlia.exceptions.RoutingException;
|
||||
@ -43,7 +44,7 @@ public class ContentLookupOperation implements Operation, Receiver
|
||||
|
||||
private final KadServer server;
|
||||
private final JKademliaNode localNode;
|
||||
private KademliaStorageEntry contentFound = null;
|
||||
private JKademliaStorageEntry contentFound = null;
|
||||
private final KadConfiguration config;
|
||||
|
||||
private final ContentLookupMessage lookupMessage;
|
||||
@ -253,7 +254,7 @@ public class ContentLookupOperation implements Operation, Receiver
|
||||
this.localNode.getRoutingTable().insert(msg.getOrigin());
|
||||
|
||||
/* Get the Content and check if it satisfies the required parameters */
|
||||
KademliaStorageEntry content = msg.getContent();
|
||||
JKademliaStorageEntry content = msg.getContent();
|
||||
this.contentFound = content;
|
||||
this.isContentFound = true;
|
||||
}
|
||||
@ -320,7 +321,7 @@ public class ContentLookupOperation implements Operation, Receiver
|
||||
*
|
||||
* @throws kademlia.exceptions.ContentNotFoundException
|
||||
*/
|
||||
public KademliaStorageEntry getContentFound() throws ContentNotFoundException
|
||||
public JKademliaStorageEntry getContentFound() throws ContentNotFoundException
|
||||
{
|
||||
if (this.isContentFound)
|
||||
{
|
||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||
import kademlia.KadConfiguration;
|
||||
import kademlia.KadServer;
|
||||
import kademlia.KademliaNode;
|
||||
import kademlia.dht.JKademliaStorageEntry;
|
||||
import kademlia.dht.KademliaDHT;
|
||||
import kademlia.dht.KademliaStorageEntry;
|
||||
import kademlia.message.Message;
|
||||
@ -22,7 +23,7 @@ public class StoreOperation implements Operation
|
||||
|
||||
private final KadServer server;
|
||||
private final KademliaNode localNode;
|
||||
private final KademliaStorageEntry storageEntry;
|
||||
private final JKademliaStorageEntry storageEntry;
|
||||
private final KademliaDHT localDht;
|
||||
private final KadConfiguration config;
|
||||
|
||||
@ -33,7 +34,7 @@ public class StoreOperation implements Operation
|
||||
* @param localDht The local DHT
|
||||
* @param config
|
||||
*/
|
||||
public StoreOperation(KadServer server, KademliaNode localNode, KademliaStorageEntry storageEntry, KademliaDHT localDht, KadConfiguration config)
|
||||
public StoreOperation(KadServer server, KademliaNode localNode, JKademliaStorageEntry storageEntry, KademliaDHT localDht, KadConfiguration config)
|
||||
{
|
||||
this.server = server;
|
||||
this.localNode = localNode;
|
||||
|
Loading…
Reference in New Issue
Block a user