mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-11-21 17:52:21 +00:00
Changed StorageEntry to store content in String format since it's smaller
This commit is contained in:
parent
b49e8170f5
commit
b7c75c4e38
@ -9,7 +9,7 @@ package kademlia.dht;
|
||||
public class StorageEntry
|
||||
{
|
||||
|
||||
private final byte[] content;
|
||||
private final String content;
|
||||
private final StorageEntryMetadata metadata;
|
||||
|
||||
public StorageEntry(KadContent content)
|
||||
@ -19,20 +19,15 @@ public class StorageEntry
|
||||
|
||||
public StorageEntry(KadContent content, StorageEntryMetadata metadata)
|
||||
{
|
||||
this.content = content.toBytes();
|
||||
this.content = new String(content.toBytes());
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public byte[] getContent()
|
||||
|
||||
public String getContent()
|
||||
{
|
||||
return this.content;
|
||||
}
|
||||
|
||||
public String getContentString()
|
||||
{
|
||||
return new String(this.content);
|
||||
}
|
||||
|
||||
public StorageEntryMetadata getContentMetadata()
|
||||
{
|
||||
return this.metadata;
|
||||
|
@ -48,7 +48,7 @@ public class ContentSendingTest
|
||||
gp.setOwnerId(c.getOwnerId());
|
||||
System.out.println("Get Parameter: " + gp);
|
||||
StorageEntry conte = kad2.get(gp);
|
||||
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContentString().getBytes()));
|
||||
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContent().getBytes()));
|
||||
System.out.println("Content Metadata: " + conte.getContentMetadata());
|
||||
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class ContentUpdatingTest
|
||||
|
||||
System.out.println("Get Parameter: " + gp);
|
||||
StorageEntry conte = kad2.get(gp);
|
||||
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContentString().getBytes()));
|
||||
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContent().getBytes()));
|
||||
System.out.println("Content Metadata: " + conte.getContentMetadata());
|
||||
|
||||
/* Lets update the content and put it again */
|
||||
@ -47,7 +47,7 @@ public class ContentUpdatingTest
|
||||
/* Lets retrieve the content */
|
||||
System.out.println("Retrieving Content Again");
|
||||
conte = kad2.get(gp);
|
||||
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContentString().getBytes()));
|
||||
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContent().getBytes()));
|
||||
System.out.println("Content Metadata: " + conte.getContentMetadata());
|
||||
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public class SaveStateTest2
|
||||
/* Trying to get a content stored on the restored node */
|
||||
GetParameter gp = new GetParameter(c.getKey(), kad2.getOwnerId(), c.getType());
|
||||
StorageEntry content = kad2.get(gp);
|
||||
DHTContentImpl cc = new DHTContentImpl().fromBytes(content.getContentString().getBytes());
|
||||
DHTContentImpl cc = new DHTContentImpl().fromBytes(content.getContent().getBytes());
|
||||
System.out.println("Content received: " + cc);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user