mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-12-23 08:11:47 +00:00
Started working on the ContentRefreshOperation
- Setup a method to get all storage entries for the different content - Started setting up the content refresh operation functionality
This commit is contained in:
parent
689a35b7bf
commit
a97905e431
@ -79,8 +79,8 @@ public class Kademlia
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Runs a RefreshOperation to refresh K-Buckets and stored content */
|
||||
new BucketRefreshOperation(server, localNode).execute();
|
||||
/* Runs a DHT RefreshOperation */
|
||||
Kademlia.this.refresh();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
@ -182,7 +182,7 @@ public class Kademlia
|
||||
*/
|
||||
public void refresh() throws IOException
|
||||
{
|
||||
new KadRefreshOperation(server, localNode).execute();
|
||||
new KadRefreshOperation(this.server, this.localNode, this.dht).execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7,6 +7,7 @@ import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import kademlia.core.Configuration;
|
||||
import kademlia.core.GetParameter;
|
||||
@ -77,12 +78,12 @@ public class DHT
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the List<StorageEntry> for the content if any exist,
|
||||
* retrieve the content from the storage system and return it
|
||||
* Get the StorageEntry for the content if any exist,
|
||||
* retrieve the KadContent from the storage system and return it
|
||||
*
|
||||
* @param param The parameters used to filter the content needed
|
||||
*
|
||||
* @return List<KadContent> A list with the content found on the DHT satisfying the given criteria
|
||||
* @return KadContent A KadContent found on the DHT satisfying the given criteria
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@ -142,4 +143,12 @@ public class DHT
|
||||
|
||||
return mainStorageFolder + File.separator + folderName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A List of all StorageEntries for this node
|
||||
*/
|
||||
public List<StorageEntry> getStorageEntries()
|
||||
{
|
||||
return entriesManager.getAllEntries();
|
||||
}
|
||||
}
|
||||
|
@ -99,4 +99,21 @@ public class StorageEntryManager
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A list of all storage entries
|
||||
*/
|
||||
public List<StorageEntry> getAllEntries()
|
||||
{
|
||||
List<StorageEntry> entriesRet = new ArrayList<>();
|
||||
|
||||
for (List<StorageEntry> entrySet : this.entries.values())
|
||||
{
|
||||
if (entrySet.size() > 0)
|
||||
{
|
||||
entriesRet.addAll(entrySet);
|
||||
}
|
||||
}
|
||||
|
||||
return entriesRet;
|
||||
}
|
||||
}
|
||||
|
@ -50,8 +50,7 @@ public class BucketRefreshOperation implements Operation
|
||||
{
|
||||
try
|
||||
{
|
||||
System.out.println("Distance: " + localNode.getNodeId().getDistance(current) + " - ID: " + current);
|
||||
|
||||
//System.out.println("Distance: " + localNode.getNodeId().getDistance(current) + " - ID: " + current);
|
||||
new NodeLookupOperation(server, localNode, localNode.getNodeId()).execute();
|
||||
}
|
||||
catch (IOException e)
|
||||
|
@ -1,19 +1,42 @@
|
||||
package kademlia.operation;
|
||||
|
||||
import kademlia.core.KadServer;
|
||||
import kademlia.dht.DHT;
|
||||
import kademlia.node.Node;
|
||||
|
||||
/**
|
||||
* Refresh the data on this node by sending the data to the K-Closest nodes to the data
|
||||
* Refresh/Restore the data on this node by sending the data to the K-Closest nodes to the data
|
||||
*
|
||||
* @author Joshua Kissoon
|
||||
* @since 20140306
|
||||
*/
|
||||
public class ContentRefreshOperation
|
||||
public class ContentRefreshOperation implements Operation
|
||||
{
|
||||
|
||||
private final KadServer server;
|
||||
private final Node localNode;
|
||||
private final DHT dht;
|
||||
|
||||
public ContentRefreshOperation(KadServer server, Node localNode, DHT dht)
|
||||
{
|
||||
this.server = server;
|
||||
this.localNode = localNode;
|
||||
this.dht = dht;
|
||||
}
|
||||
|
||||
/**
|
||||
* For each content stored on this DHT, distribute it to the K closest nodes
|
||||
* Also delete the content if this node is no longer one of the K closest nodes
|
||||
*
|
||||
* We assume that our RoutingTable is updated, and we can get the K closest nodes from that table
|
||||
*/
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
|
||||
/**
|
||||
* @todo Delete any content on this node that this node is not one of the K-Closest nodes to
|
||||
* @todo Delete any expired content
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package kademlia.operation;
|
||||
|
||||
import java.io.IOException;
|
||||
import kademlia.core.KadServer;
|
||||
import kademlia.dht.DHT;
|
||||
import kademlia.node.Node;
|
||||
|
||||
/**
|
||||
@ -15,11 +16,13 @@ public class KadRefreshOperation implements Operation
|
||||
|
||||
private final KadServer server;
|
||||
private final Node localNode;
|
||||
private final DHT dht;
|
||||
|
||||
public KadRefreshOperation(KadServer server, Node localNode)
|
||||
public KadRefreshOperation(KadServer server, Node localNode, DHT dht)
|
||||
{
|
||||
this.server = server;
|
||||
this.localNode = localNode;
|
||||
this.dht = dht;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -27,7 +30,8 @@ public class KadRefreshOperation implements Operation
|
||||
{
|
||||
/* Run our BucketRefreshOperation to refresh buckets */
|
||||
new BucketRefreshOperation(server, localNode).execute();
|
||||
|
||||
|
||||
/* After buckets have been refreshed, we refresh content */
|
||||
new ContentRefreshOperation(server, localNode, dht).execute();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user