2014-02-24 15:56:49 +00:00
|
|
|
package kademlia.operation;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2014-03-06 05:51:08 +00:00
|
|
|
import java.util.List;
|
2014-02-24 15:56:49 +00:00
|
|
|
import kademlia.core.KadServer;
|
|
|
|
import kademlia.node.Node;
|
2014-03-06 05:51:08 +00:00
|
|
|
import kademlia.node.NodeId;
|
2014-02-24 15:56:49 +00:00
|
|
|
|
|
|
|
/**
|
2014-03-06 05:51:08 +00:00
|
|
|
* At each time interval t, nodes need to refresh their K-Buckets
|
|
|
|
* This operation takes care of refreshing this node's K-Buckets
|
2014-02-24 15:56:49 +00:00
|
|
|
*
|
|
|
|
* @author Joshua Kissoon
|
|
|
|
* @created 20140224
|
|
|
|
*/
|
2014-03-06 05:51:08 +00:00
|
|
|
public class BucketRefreshOperation implements Operation
|
2014-02-24 15:56:49 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
private final KadServer server;
|
|
|
|
private final Node localNode;
|
|
|
|
|
2014-03-06 05:51:08 +00:00
|
|
|
public BucketRefreshOperation(KadServer server, Node localNode)
|
2014-02-24 15:56:49 +00:00
|
|
|
{
|
|
|
|
this.server = server;
|
|
|
|
this.localNode = localNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-26 13:28:55 +00:00
|
|
|
public synchronized void execute() throws IOException
|
2014-02-24 15:56:49 +00:00
|
|
|
{
|
2014-03-06 05:51:08 +00:00
|
|
|
System.out.println("Bucket Refresh Operation Started");
|
|
|
|
|
|
|
|
/* Get a list of NodeIds for each distance from the LocalNode NodeId */
|
|
|
|
List<NodeId> refreshIds = this.localNode.getRoutingTable().getRefreshList();
|
|
|
|
|
|
|
|
/* Test whether each nodeId in this list is a different distance from our current NID */
|
|
|
|
for (NodeId nid : refreshIds)
|
|
|
|
{
|
2014-03-06 07:19:15 +00:00
|
|
|
System.out.println(localNode.getNodeId().getDistance(nid));
|
2014-03-06 05:51:08 +00:00
|
|
|
}
|
|
|
|
|
2014-02-24 15:56:49 +00:00
|
|
|
/* @todo Do a Node Lookup operation to refresh K-Buckets */
|
|
|
|
new NodeLookupOperation(this.server, this.localNode, this.localNode.getNodeId()).execute();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @todo Send data in DHT to closest Nodes if they don't have it
|
|
|
|
* This is better than asking closest nodes for data,
|
|
|
|
* since the data may not always come from the closest nodes
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|