Storage Entry Usage

- Now we manage storage entries directly from the KadNode 
- rather than creating them all over the place
This commit is contained in:
Joshua Kissoon 2014-05-11 15:39:43 +05:30
parent 7b95d03d96
commit 24abfe3d2a
2 changed files with 27 additions and 11 deletions

View File

@ -289,7 +289,23 @@ public class KademliaNode
*/
public int put(KadContent content) throws IOException
{
StoreOperation sop = new StoreOperation(this.server, this, content, this.dht, this.config);
return this.put(new StorageEntry(content));
}
/**
* Stores the specified value under the given key
* This value is stored on K nodes on the network, or all nodes if there are > K total nodes in the network
*
* @param entry The StorageEntry with the content to put onto the DHT
*
* @return Integer How many nodes the content was stored on
*
* @throws java.io.IOException
*
*/
private int put(StorageEntry entry) throws IOException
{
StoreOperation sop = new StoreOperation(this.server, this, entry, this.dht, this.config);
sop.execute();
/* Return how many nodes the content was stored on */
@ -305,7 +321,7 @@ public class KademliaNode
*/
public void putLocally(KadContent content) throws IOException
{
this.dht.store(content);
this.dht.store(new StorageEntry(content));
}
/**

View File

@ -23,22 +23,22 @@ public class StoreOperation implements Operation
private final KadServer server;
private final KademliaNode localNode;
private final KadContent content;
private final StorageEntry storageEntry;
private final DHT localDht;
private final KadConfiguration config;
/**
* @param server
* @param localNode
* @param content The content to be stored on the DHT
* @param localDht The local DHT
* @param storageEntry The content to be stored on the DHT
* @param localDht The local DHT
* @param config
*/
public StoreOperation(KadServer server, KademliaNode localNode, KadContent content, DHT localDht, KadConfiguration config)
public StoreOperation(KadServer server, KademliaNode localNode, StorageEntry storageEntry, DHT localDht, KadConfiguration config)
{
this.server = server;
this.localNode = localNode;
this.content = content;
this.storageEntry = storageEntry;
this.localDht = localDht;
this.config = config;
}
@ -47,20 +47,20 @@ public class StoreOperation implements Operation
public synchronized void execute() throws IOException
{
/* Get the nodes on which we need to store the content */
NodeLookupOperation ndlo = new NodeLookupOperation(this.server, this.localNode, this.content.getKey(), this.config);
NodeLookupOperation ndlo = new NodeLookupOperation(this.server, this.localNode, this.storageEntry.getContentMetadata().getKey(), this.config);
ndlo.execute();
List<Node> nodes = ndlo.getClosestNodes();
/* Create the message */
Message msg = new StoreContentMessage(this.localNode.getNode(), new StorageEntry(this.content));
Message msg = new StoreContentMessage(this.localNode.getNode(), this.storageEntry);
/*Store the message on all of the K-Nodes*/
for (Node n : nodes)
{
if (n.equals(this.localNode))
if (n.equals(this.localNode.getNode()))
{
/* Store the content locally */
this.localDht.store(content);
this.localDht.store(this.storageEntry);
}
else
{