mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-11-22 18:22:19 +00:00
54ac3fe740
Kademlia Node - The Kademlia class is renamed to KademliaNode - this will now serve as the main node on the network - The RoutingTable will be a part of this node Node - The node class is now a basic class containing information about a node to be used by peers on the network RoutingTable - Working on Evicting contacts from the routing table - Working on Replacement Cache - Written another simulation to test these new RoutingTable features
85 lines
2.4 KiB
Java
85 lines
2.4 KiB
Java
package kademlia.operation;
|
|
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
import kademlia.KademliaNode;
|
|
import kademlia.core.KadConfiguration;
|
|
import kademlia.core.KadServer;
|
|
import kademlia.dht.DHT;
|
|
import kademlia.dht.KadContent;
|
|
import kademlia.dht.StorageEntry;
|
|
import kademlia.message.Message;
|
|
import kademlia.message.StoreContentMessage;
|
|
import kademlia.node.Node;
|
|
|
|
/**
|
|
* Operation that stores a DHT Content onto the K closest nodes to the content Key
|
|
*
|
|
* @author Joshua Kissoon
|
|
* @since 20140224
|
|
*/
|
|
public class StoreOperation implements Operation
|
|
{
|
|
|
|
private final KadServer server;
|
|
private final KademliaNode localNode;
|
|
private final KadContent content;
|
|
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 config
|
|
*/
|
|
public StoreOperation(KadServer server, KademliaNode localNode, KadContent content, DHT localDht, KadConfiguration config)
|
|
{
|
|
this.server = server;
|
|
this.localNode = localNode;
|
|
this.content = content;
|
|
this.localDht = localDht;
|
|
this.config = config;
|
|
}
|
|
|
|
@Override
|
|
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);
|
|
ndlo.execute();
|
|
List<Node> nodes = ndlo.getClosestNodes();
|
|
|
|
/* Create the message */
|
|
Message msg = new StoreContentMessage(this.localNode.getNode(), new StorageEntry(this.content));
|
|
|
|
/*Store the message on all of the K-Nodes*/
|
|
for (Node n : nodes)
|
|
{
|
|
if (n.equals(this.localNode))
|
|
{
|
|
/* Store the content locally */
|
|
this.localDht.store(content);
|
|
}
|
|
else
|
|
{
|
|
/**
|
|
* @todo Create a receiver that receives a store acknowledgement message to count how many nodes a content have been stored at
|
|
*/
|
|
this.server.sendMessage(n, msg, null);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return The number of nodes that have stored this content
|
|
*
|
|
* @todo Implement this method
|
|
*/
|
|
public int numNodesStoredAt()
|
|
{
|
|
return 1;
|
|
}
|
|
}
|