diff --git a/src/kademlia/KademliaNode.java b/src/kademlia/KademliaNode.java index 277d4bf..586e94c 100644 --- a/src/kademlia/KademliaNode.java +++ b/src/kademlia/KademliaNode.java @@ -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)); } /** diff --git a/src/kademlia/operation/StoreOperation.java b/src/kademlia/operation/StoreOperation.java index c43eae2..09f4dc3 100644 --- a/src/kademlia/operation/StoreOperation.java +++ b/src/kademlia/operation/StoreOperation.java @@ -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 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 {