mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-11-22 02:02:21 +00:00
Manage content in byte format since strings may have encoding problems! especially for compression, etc
This commit is contained in:
parent
66321280e6
commit
cc0cdc42b5
@ -9,7 +9,7 @@ package kademlia.dht;
|
|||||||
public class StorageEntry
|
public class StorageEntry
|
||||||
{
|
{
|
||||||
|
|
||||||
private String content;
|
private byte[] content;
|
||||||
private final StorageEntryMetadata metadata;
|
private final StorageEntryMetadata metadata;
|
||||||
|
|
||||||
public StorageEntry(KadContent content)
|
public StorageEntry(KadContent content)
|
||||||
@ -19,16 +19,16 @@ public class StorageEntry
|
|||||||
|
|
||||||
public StorageEntry(KadContent content, StorageEntryMetadata metadata)
|
public StorageEntry(KadContent content, StorageEntryMetadata metadata)
|
||||||
{
|
{
|
||||||
this.content = new String(content.toBytes());
|
this.content = content.toBytes();
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContent(String data)
|
public void setContent(byte[] data)
|
||||||
{
|
{
|
||||||
this.content = data;
|
this.content = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getContent()
|
public byte[] getContent()
|
||||||
{
|
{
|
||||||
return this.content;
|
return this.content;
|
||||||
}
|
}
|
||||||
@ -38,6 +38,7 @@ public class StorageEntry
|
|||||||
return this.metadata;
|
return this.metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder("[StorageEntry: ");
|
StringBuilder sb = new StringBuilder("[StorageEntry: ");
|
||||||
|
@ -48,7 +48,7 @@ public class ContentSendingTest
|
|||||||
gp.setOwnerId(c.getOwnerId());
|
gp.setOwnerId(c.getOwnerId());
|
||||||
System.out.println("Get Parameter: " + gp);
|
System.out.println("Get Parameter: " + gp);
|
||||||
StorageEntry conte = kad2.get(gp);
|
StorageEntry conte = kad2.get(gp);
|
||||||
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContent().getBytes()));
|
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContent()));
|
||||||
System.out.println("Content Metadata: " + conte.getContentMetadata());
|
System.out.println("Content Metadata: " + conte.getContentMetadata());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ public class ContentUpdatingTest
|
|||||||
|
|
||||||
System.out.println("Get Parameter: " + gp);
|
System.out.println("Get Parameter: " + gp);
|
||||||
StorageEntry conte = kad2.get(gp);
|
StorageEntry conte = kad2.get(gp);
|
||||||
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContent().getBytes()));
|
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContent()));
|
||||||
System.out.println("Content Metadata: " + conte.getContentMetadata());
|
System.out.println("Content Metadata: " + conte.getContentMetadata());
|
||||||
|
|
||||||
/* Lets update the content and put it again */
|
/* Lets update the content and put it again */
|
||||||
@ -47,7 +47,7 @@ public class ContentUpdatingTest
|
|||||||
/* Lets retrieve the content */
|
/* Lets retrieve the content */
|
||||||
System.out.println("Retrieving Content Again");
|
System.out.println("Retrieving Content Again");
|
||||||
conte = kad2.get(gp);
|
conte = kad2.get(gp);
|
||||||
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContent().getBytes()));
|
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContent()));
|
||||||
System.out.println("Content Metadata: " + conte.getContentMetadata());
|
System.out.println("Content Metadata: " + conte.getContentMetadata());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ public class SaveStateTest2
|
|||||||
/* Trying to get a content stored on the restored node */
|
/* Trying to get a content stored on the restored node */
|
||||||
GetParameter gp = new GetParameter(c.getKey(), kad2.getOwnerId(), c.getType());
|
GetParameter gp = new GetParameter(c.getKey(), kad2.getOwnerId(), c.getType());
|
||||||
StorageEntry content = kad2.get(gp);
|
StorageEntry content = kad2.get(gp);
|
||||||
DHTContentImpl cc = new DHTContentImpl().fromBytes(content.getContent().getBytes());
|
DHTContentImpl cc = new DHTContentImpl().fromBytes(content.getContent());
|
||||||
System.out.println("Content received: " + cc);
|
System.out.println("Content received: " + cc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user